call.h 8.23 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
36
typedef std::string CallID;

class Call{
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  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
58

yanmorin's avatar
   
yanmorin committed
59
60
61
62
63
64
65
    /**
     * 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
66

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

yanmorin's avatar
   
yanmorin committed
73
74
75
76
77
78
    /** 
     * 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; }
79
80
81
82
83
84

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

238
  protected:
yanmorin's avatar
   
yanmorin committed
239
240
    /** Protect every attribute that can be changed by two threads */
    ost::Mutex _callMutex;
jpbl's avatar
jpbl committed
241

242
243
244
245
    /** 
     * Set remote's IP addr. [not protected]
     * @param ip  The remote IP address
     */
246
247
    void setRemoteIP(const std::string& ip)    { _remoteIPAddress = ip; }

248
249
250
251
    /** 
     * Set remote's audio port. [not protected]
     * @param port  The remote audio port
     */
252
253
    void setRemoteAudioPort(unsigned int port) { _remoteAudioPort = port; }

254
255
256
257
    /** 
     * Set the audio codec used.  [not protected] 
     * @param audioCodec  The payload of the codec
     */
258
    void setAudioCodec(AudioCodecType audioCodec) { _audioCodec = audioCodec; }
259
260

    /** Codec Map */
261
    CodecDescriptor _codecMap;
262
263

    /** Codec pointer */
264
    AudioCodecType _audioCodec;
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

    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;


286
  private:  
287
  
yanmorin's avatar
   
yanmorin committed
288
289
    /** Unique ID of the call */
    CallID _id;
jpbl's avatar
jpbl committed
290

yanmorin's avatar
   
yanmorin committed
291
292
293
294
295
296
    /** 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
297

yanmorin's avatar
   
yanmorin committed
298
299
    /** Name of the peer */
    std::string _peerName;
jpbl's avatar
jpbl committed
300

yanmorin's avatar
   
yanmorin committed
301
302
    /** Number of the peer */
    std::string _peerNumber;
303

304
305
    /** File name for his call : time YY-MM-DD */
    std::string _filename;
jpbl's avatar
jpbl committed
306
307
};

yanmorin's avatar
   
yanmorin committed
308
#endif