call.h 7.65 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

25
#include "audio/codecDescriptor.h"
yanmorin's avatar
   
yanmorin committed
26

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

211
  protected:
yanmorin's avatar
   
yanmorin committed
212
213
    /** Protect every attribute that can be changed by two threads */
    ost::Mutex _callMutex;
jpbl's avatar
jpbl committed
214

215
216
217
218
    /** 
     * Set remote's IP addr. [not protected]
     * @param ip  The remote IP address
     */
219
220
    void setRemoteIP(const std::string& ip)    { _remoteIPAddress = ip; }

221
222
223
224
    /** 
     * Set remote's audio port. [not protected]
     * @param port  The remote audio port
     */
225
226
    void setRemoteAudioPort(unsigned int port) { _remoteAudioPort = port; }

227
228
229
230
    /** 
     * Set the audio codec used.  [not protected] 
     * @param audioCodec  The payload of the codec
     */
231
    void setAudioCodec(AudioCodecType audioCodec) { _audioCodec = audioCodec; }
232
233

    /** Codec Map */
234
    CodecDescriptor _codecMap;
235
236

    /** Codec pointer */
237
    AudioCodecType _audioCodec;
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

    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;


259
  private:  
yanmorin's avatar
   
yanmorin committed
260
261
    /** Unique ID of the call */
    CallID _id;
jpbl's avatar
jpbl committed
262

yanmorin's avatar
   
yanmorin committed
263
264
265
266
267
268
    /** 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
269

yanmorin's avatar
   
yanmorin committed
270
271
    /** Name of the peer */
    std::string _peerName;
jpbl's avatar
jpbl committed
272

yanmorin's avatar
   
yanmorin committed
273
274
    /** Number of the peer */
    std::string _peerNumber;
275

jpbl's avatar
jpbl committed
276
277
};

yanmorin's avatar
   
yanmorin committed
278
#endif