call.h 8.3 KB
Newer Older
yanmorin's avatar
   
yanmorin committed
1
2
/*
 *  Copyright (C) 2004-2006 Savoir-Faire Linux inc.
jpbl's avatar
jpbl committed
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
yanmorin's avatar
   
yanmorin committed
4
5
 *  Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com>
 *
jpbl's avatar
jpbl committed
6
7
 *  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
8
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
9
 *  (at your option) any later version.
yanmorin's avatar
   
yanmorin committed
10
 *
jpbl's avatar
jpbl committed
11
12
13
14
 *  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.
yanmorin's avatar
   
yanmorin committed
15
 *
jpbl's avatar
jpbl committed
16
17
18
19
 *  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.
 */
yanmorin's avatar
   
yanmorin committed
20
21
#ifndef CALL_H
#define CALL_H
jpbl's avatar
jpbl committed
22

yanmorin's avatar
   
yanmorin committed
23
#include <cc++/thread.h> // for mutex
24
#include <sstream>
25

26
#include "audio/codecDescriptor.h"
27
#include "plug-in/audiorecorder/audiorecord.h"
yanmorin's avatar
   
yanmorin committed
28

29
30
31
32
33
/* 
 * @file call.h 
 * @brief A call is the base class for protocol-based calls
 */

yanmorin's avatar
   
yanmorin committed
34
35
typedef std::string CallID;

36
37
class AudioRecord;

yanmorin's avatar
   
yanmorin committed
38
class Call{
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  public:
    /**
     * This determines if the call originated from the local user (Outgoing)
     * or from some remote peer (Incoming).
     */
    enum CallType {Incoming, Outgoing};

    /**
     * Tell where we're at with the call. The call gets Connected when we know
     * from the other end what happened with out call. A call can be 'Connected'
     * even if the call state is Busy, Refused, or Error.
     *
     * Audio should be transmitted when ConnectionState = Connected AND
     * CallState = Active.
     */
    enum ConnectionState {Disconnected, Trying, Progressing, Ringing, Connected};

    /**
     * The Call State.
     */
    enum CallState {Inactive, Active, Hold, Busy, Refused, Error};
jpbl's avatar
jpbl committed
60

yanmorin's avatar
   
yanmorin committed
61
62
63
64
65
66
67
    /**
     * Constructor of a call
     * @param id Unique identifier of the call
     * @param type set definitely this call as incoming/outgoing
     */
    Call(const CallID& id, Call::CallType type);
    virtual ~Call();
jpbl's avatar
jpbl committed
68

yanmorin's avatar
   
yanmorin committed
69
70
71
72
73
    /** 
     * Return a reference on the call id
     * @return call id
     */
    CallID& getCallId() {return _id; }
jpbl's avatar
jpbl committed
74

yanmorin's avatar
   
yanmorin committed
75
76
77
78
79
80
    /** 
     * Set the peer number (destination on outgoing)
     * not protected by mutex (when created)
     * @param number peer number
     */
    void setPeerNumber(const std::string& number) {  _peerNumber = number; }
81
82
83
84
85
86

    /** 
     * Get the peer number (destination on outgoing)
     * not protected by mutex (when created)
     * @return std::string The peer number
     */
yanmorin's avatar
   
yanmorin committed
87
    const std::string& getPeerNumber() {  return _peerNumber; }
jpbl's avatar
jpbl committed
88

yanmorin's avatar
   
yanmorin committed
89
90
91
    /** 
     * Set the peer name (caller in ingoing)
     * not protected by mutex (when created)
92
     * @param name The peer name
yanmorin's avatar
   
yanmorin committed
93
94
     */
    void setPeerName(const std::string& name) {  _peerName = name; }
95
96
97
98
99
100

    /** 
     * Get the peer name (caller in ingoing)
     * not protected by mutex (when created)
     * @return std::string The peer name
     */
yanmorin's avatar
   
yanmorin committed
101
102
    const std::string& getPeerName() {  return _peerName; }

yanmorin's avatar
   
yanmorin committed
103
104
    /**
     * Tell if the call is incoming
105
106
     * @return true if yes
     *	      false otherwise
yanmorin's avatar
   
yanmorin committed
107
108
109
     */
    bool isIncoming() { return (_type == Incoming) ? true : false; }

yanmorin's avatar
   
yanmorin committed
110
111
    /** 
     * Set the connection state of the call (protected by mutex)
112
     * @param state The connection state
yanmorin's avatar
   
yanmorin committed
113
114
     */
    void setConnectionState(ConnectionState state);
115
    
yanmorin's avatar
   
yanmorin committed
116
    /** 
117
118
     * Get the connection state of the call (protected by mutex)
     * @return ConnectionState The connection state
yanmorin's avatar
   
yanmorin committed
119
120
     */
    ConnectionState getConnectionState();
yanmorin's avatar
   
yanmorin committed
121

yanmorin's avatar
   
yanmorin committed
122
123
    /**
     * Set the state of the call (protected by mutex)
124
     * @param state The call state
yanmorin's avatar
   
yanmorin committed
125
126
     */
    void setState(CallState state);
127

yanmorin's avatar
   
yanmorin committed
128
    /** 
129
130
     * Get the call state of the call (protected by mutex)
     * @return CallState  The call state
yanmorin's avatar
   
yanmorin committed
131
132
     */
    CallState getState();
jpbl's avatar
jpbl committed
133

134
135
136
    /**
     * Set the audio start boolean (protected by mutex)
     * @param start true if we start the audio
137
     *		    false otherwise
138
139
140
141
142
143
     */
    void setAudioStart(bool start);

    /**
     * Tell if the audio is started (protected by mutex)
     * @return true if it's already started
144
     *	      false otherwise
145
146
147
148
     */
    bool isAudioStarted();

    // AUDIO
149
150
151
152
    /** 
     * Set internal codec Map: initialization only, not protected 
     * @param map The codec map
     */
153
    void setCodecMap(const CodecDescriptor& map) { _codecMap = map; } 
154
155
156
157
158

    /** 
     * Get internal codec Map: initialization only, not protected 
     * @return CodecDescriptor	The codec map
     */
159
    CodecDescriptor& getCodecMap();
160

161
162
163
164
    /** 
     * Set my IP [not protected] 
     * @param ip  The local IP address
     */
165
166
    void setLocalIp(const std::string& ip)     { _localIPAddress = ip; }

167
168
169
170
    /** 
     * Set local audio port, as seen by me [not protected]
     * @param port  The local audio port
     */
171
172
    void setLocalAudioPort(unsigned int port)  { _localAudioPort = port;}

173
174
175
176
    /** 
     * Set the audio port that remote will see.
     * @param port  The external audio port
     */
177
178
    void setLocalExternAudioPort(unsigned int port) { _localExternalAudioPort = port; }

179
180
181
182
    /** 
     * Return the audio port seen by the remote side. 
     * @return unsigned int The external audio port
    */
183
184
    unsigned int getLocalExternAudioPort() { return _localExternalAudioPort; }

185
186
187
188
    /** 
     * Return my IP [mutex protected] 
     * @return std::string The local IP
     */
189
    const std::string& getLocalIp();
190
191
192
193
194

    /** 
     * Return port used locally (for my machine) [mutex protected] 
     * @return unsigned int  The local audio port
     */
195
    unsigned int getLocalAudioPort();
196
197
198
199
200

    /** 
     * Return audio port at destination [mutex protected] 
     * @return unsigned int The remote audio port
     */
201
202
    unsigned int getRemoteAudioPort();

203
204
205
206
    /** 
     * Return IP of destination [mutex protected]
     * @return const std:string	The remote IP address
     */
207
208
    const std::string& getRemoteIp();

209
210
211
212
    /** 
     * Return audio codec [mutex protected]
     * @return AudioCodecType The payload of the codec
     */
213
    AudioCodecType getAudioCodec();
214

215
216
217
218
219
220
    /**
     * @return Return the file name for this call
     */
    std::string getFileName() {return _filename;}

    /**
221
     * A recorder for this call
222
     */
223
224
225
226
227
228
    AudioRecord recAudio;
  
    /**
     * SetRecording
     */
    void setRecording();
229
230
231
232
233

    /**
     * stopRecording, make sure the recording is stopped (whe transfering call)
     */
    void stopRecording();
alexandresavard's avatar
alexandresavard committed
234
235
236
237
238
    
    /**
     * Return Recording state
     */
    bool isRecording(); 
239

240
241
242
243
244
    /**
     *
     */
    void initRecFileName();

245
  protected:
yanmorin's avatar
   
yanmorin committed
246
247
    /** Protect every attribute that can be changed by two threads */
    ost::Mutex _callMutex;
jpbl's avatar
jpbl committed
248

249
250
251
252
    /** 
     * Set remote's IP addr. [not protected]
     * @param ip  The remote IP address
     */
253
254
    void setRemoteIP(const std::string& ip)    { _remoteIPAddress = ip; }

255
256
257
258
    /** 
     * Set remote's audio port. [not protected]
     * @param port  The remote audio port
     */
259
260
    void setRemoteAudioPort(unsigned int port) { _remoteAudioPort = port; }

261
262
263
264
    /** 
     * Set the audio codec used.  [not protected] 
     * @param audioCodec  The payload of the codec
     */
265
    void setAudioCodec(AudioCodecType audioCodec) { _audioCodec = audioCodec; }
266
267

    /** Codec Map */
268
    CodecDescriptor _codecMap;
269
270

    /** Codec pointer */
271
    AudioCodecType _audioCodec;
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

    bool _audioStarted;

    // Informations about call socket / audio

    /** My IP address */
    std::string  _localIPAddress;

    /** Local audio port, as seen by me. */
    unsigned int _localAudioPort;

    /** Port assigned to my machine by the NAT, as seen by remote peer (he connects there) */
    unsigned int _localExternalAudioPort;

    /** Remote's IP address */
    std::string  _remoteIPAddress;

    /** Remote's audio port */
    unsigned int _remoteAudioPort;


293
  private:  
294
  
yanmorin's avatar
   
yanmorin committed
295
296
    /** Unique ID of the call */
    CallID _id;
jpbl's avatar
jpbl committed
297

yanmorin's avatar
   
yanmorin committed
298
299
300
301
302
303
    /** Type of the call */
    CallType _type;
    /** Disconnected/Progressing/Trying/Ringing/Connected */
    ConnectionState _connectionState;
    /** Inactive/Active/Hold/Busy/Refused/Error */
    CallState _callState;
jpbl's avatar
jpbl committed
304

yanmorin's avatar
   
yanmorin committed
305
306
    /** Name of the peer */
    std::string _peerName;
jpbl's avatar
jpbl committed
307

yanmorin's avatar
   
yanmorin committed
308
309
    /** Number of the peer */
    std::string _peerNumber;
310

311
312
    /** File name for his call : time YY-MM-DD */
    std::string _filename;
jpbl's avatar
jpbl committed
313
314
};

yanmorin's avatar
   
yanmorin committed
315
#endif