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

23
24
25
/* @file call.h 
 * @brief A call is the base class for protocol-based calls
 */
jpbl's avatar
jpbl committed
26
#include <string>
yanmorin's avatar
   
yanmorin committed
27
#include <cc++/thread.h> // for mutex
28
#include "audio/codecDescriptor.h"
yanmorin's avatar
   
yanmorin committed
29
30
31
32
33

typedef std::string CallID;

class Call{
public:
Alexandre Bourget's avatar
Alexandre Bourget committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  /**
   * 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
54

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

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

yanmorin's avatar
   
yanmorin committed
69
70
71
72
73
74
75
    /** 
     * 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
76

yanmorin's avatar
   
yanmorin committed
77
78
79
80
81
82
83
84
    /** 
     * 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
85
86
87
88
89
    /**
     * Tell if the call is incoming
     */
    bool isIncoming() { return (_type == Incoming) ? true : false; }

yanmorin's avatar
   
yanmorin committed
90
91
92
93
94
95
96
97
    /** 
     * 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
98

yanmorin's avatar
   
yanmorin committed
99
100
101
102
103
104
105
106
    /**
     * 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
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
    /**
     * 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 */
122
123
    void setCodecMap(const CodecDescriptor& map) { _codecMap = map; } 
    CodecDescriptor& getCodecMap();
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

    /** 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] */
150
    AudioCodecType getAudioCodec();
151
152
153



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

158
159
160
161
162
163
164
    /** 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] */
165
    void setAudioCodec(AudioCodecType audioCodec) { _audioCodec = audioCodec; }
166
167

    /** Codec Map */
168
    CodecDescriptor _codecMap;
169
170

    /** Codec pointer */
171
    AudioCodecType _audioCodec;
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

    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
193
194
195
private:  
    /** Unique ID of the call */
    CallID _id;
jpbl's avatar
jpbl committed
196

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

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

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

jpbl's avatar
jpbl committed
210
211
};

yanmorin's avatar
   
yanmorin committed
212
#endif