call.h 6.2 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
8
9
 *  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.
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
23

#include <string>
yanmorin's avatar
   
yanmorin committed
24
#include <cc++/thread.h> // for mutex
25
#include "audio/codecDescriptor.h"
yanmorin's avatar
   
yanmorin committed
26
27
28
29

typedef std::string CallID;

/**
30
31
 * A call is the base class for protocol-based calls
 *
yanmorin's avatar
   
yanmorin committed
32
33
 * @author Yan Morin <yan.morin@gmail.com>
 */
yanmorin's avatar
   
yanmorin committed
34
35
class Call{
public:
Alexandre Bourget's avatar
Alexandre Bourget committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  /**
   * 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
77
    /** 
     * 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; }
    const std::string& getPeerNumber() {  return _peerNumber; }
jpbl's avatar
jpbl committed
78

yanmorin's avatar
   
yanmorin committed
79
80
81
82
83
84
85
86
    /** 
     * Set the peer name (caller in ingoing)
     * not protected by mutex (when created)
     * @param number peer number
     */
    void setPeerName(const std::string& name) {  _peerName = name; }
    const std::string& getPeerName() {  return _peerName; }

yanmorin's avatar
   
yanmorin committed
87
88
89
90
91
    /**
     * Tell if the call is incoming
     */
    bool isIncoming() { return (_type == Incoming) ? true : false; }

yanmorin's avatar
   
yanmorin committed
92
93
94
95
96
97
98
99
    /** 
     * Set the connection state of the call (protected by mutex)
     */
    void setConnectionState(ConnectionState state);
    /** 
     * get the connection state of the call (protected by mutex)
     */
    ConnectionState getConnectionState();
yanmorin's avatar
   
yanmorin committed
100

yanmorin's avatar
   
yanmorin committed
101
102
103
104
105
106
107
108
    /**
     * Set the state of the call (protected by mutex)
     */
    void setState(CallState state);
    /** 
     * get the call state of the call (protected by mutex)
     */
    CallState getState();
jpbl's avatar
jpbl committed
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    /**
     * Set the audio start boolean (protected by mutex)
     * @param start true if we start the audio
     */
    void setAudioStart(bool start);

    /**
     * Tell if the audio is started (protected by mutex)
     * @return true if it's already started
     */
    bool isAudioStarted();

    // AUDIO
    /** Set internal codec Map: initialization only, not protected */
    void setCodecMap(const CodecDescriptorMap& map) { _codecMap = map; } 
    CodecDescriptorMap& getCodecMap();

    /** Set my IP [not protected] */
    void setLocalIp(const std::string& ip)     { _localIPAddress = ip; }

    /** Set local audio port, as seen by me [not protected] */
    void setLocalAudioPort(unsigned int port)  { _localAudioPort = port;}

    /** Set the audio port that remote will see. */
    void setLocalExternAudioPort(unsigned int port) { _localExternalAudioPort = port; }

    /** Return the audio port seen by the remote side. */
    unsigned int getLocalExternAudioPort() { return _localExternalAudioPort; }

    /** Return my IP [mutex protected] */
    const std::string& getLocalIp();
    
    /** Return port used locally (for my machine) [mutex protected] */
    unsigned int getLocalAudioPort();
    
    /** Return audio port at destination [mutex protected] */
    unsigned int getRemoteAudioPort();

    /** Return IP of destination [mutex protected] */
    const std::string& getRemoteIp();

    /** Return audio codec [mutex protected] */
    AudioCodec* getAudioCodec();



yanmorin's avatar
   
yanmorin committed
156
157
158
protected:
    /** Protect every attribute that can be changed by two threads */
    ost::Mutex _callMutex;
jpbl's avatar
jpbl committed
159

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
    /** Set remote's IP addr. [not protected] */
    void setRemoteIP(const std::string& ip)    { _remoteIPAddress = ip; }

    /** Set remote's audio port. [not protected] */
    void setRemoteAudioPort(unsigned int port) { _remoteAudioPort = port; }

    /** Set the audio codec used.  [not protected] */
    void setAudioCodec(AudioCodec* audioCodec) { _audioCodec = audioCodec; }

    /** Codec Map */
    CodecDescriptorMap _codecMap;

    /** Codec pointer */
    AudioCodec* _audioCodec;

    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;


yanmorin's avatar
   
yanmorin committed
195
196
197
private:  
    /** Unique ID of the call */
    CallID _id;
jpbl's avatar
jpbl committed
198

yanmorin's avatar
   
yanmorin committed
199
200
201
202
203
204
    /** 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
205

yanmorin's avatar
   
yanmorin committed
206
207
    /** Name of the peer */
    std::string _peerName;
jpbl's avatar
jpbl committed
208

yanmorin's avatar
   
yanmorin committed
209
210
    /** Number of the peer */
    std::string _peerNumber;
211

jpbl's avatar
jpbl committed
212
213
};

yanmorin's avatar
   
yanmorin committed
214
#endif