call.cpp 4.65 KB
Newer Older
yanmorin's avatar
   
yanmorin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 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
 *  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.
19
20
21
22
23
24
25
26
27
28
29
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
jpbl's avatar
jpbl committed
30
31
 */
#include "call.h"
32
#include "manager.h"
33
#include "audio/mainbuffer.h"
jpbl's avatar
jpbl committed
34

35
36
37
38
39
40
41
Call::Call (const CallID& id, Call::CallType type)
        : _callMutex()
        , _audioStarted (false)
        , _localIPAddress ("")
        , _localAudioPort (0)
        , _localExternalAudioPort (0)
        , _id (id)
Emmanuel Milou's avatar
Emmanuel Milou committed
42
        , _confID ("")
43
44
45
46
47
48
        , _type (type)
        , _connectionState (Call::Disconnected)
        , _callState (Call::Inactive)
        , _callConfig (Call::Classic)
        , _peerName()
        , _peerNumber()
jpbl's avatar
jpbl committed
49
{
50

jpbl's avatar
jpbl committed
51
52
53
}


yanmorin's avatar
   
yanmorin committed
54
Call::~Call()
jpbl's avatar
jpbl committed
55
56
57
{
}

58
59
void
Call::setConnectionState (ConnectionState state)
jpbl's avatar
jpbl committed
60
{
61
62
    ost::MutexLock m (_callMutex);
    _connectionState = state;
jpbl's avatar
jpbl committed
63
64
}

yanmorin's avatar
   
yanmorin committed
65
Call::ConnectionState
66
Call::getConnectionState()
jpbl's avatar
jpbl committed
67
{
68
69
    ost::MutexLock m (_callMutex);
    return _connectionState;
jpbl's avatar
jpbl committed
70
71
72
}


73
74
void
Call::setState (CallState state)
jpbl's avatar
jpbl committed
75
{
76
77
    ost::MutexLock m (_callMutex);
    _callState = state;
jpbl's avatar
jpbl committed
78
79
80
}

Call::CallState
81
Call::getState()
jpbl's avatar
jpbl committed
82
{
83
84
    ost::MutexLock m (_callMutex);
    return _callState;
jpbl's avatar
jpbl committed
85
86
}

87
std::string
88
Call::getStateStr ()
89
{
90
    CallState state = getState();
Emmanuel Milou's avatar
Emmanuel Milou committed
91
92
    ConnectionState connection = getConnectionState ();
    CallType type = _type;
93
    std::string state_str;
94

95
    switch (state) {
96

97
        case Active:
Emmanuel Milou's avatar
Emmanuel Milou committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

            switch (connection) {

                case Ringing:
                    (type == Incoming) ? state_str = "INCOMING":state_str = "RINGING";
                    break;

                case Connected:
                    state_str = "CURRENT";
                    break;

                default:
                    state_str = "CURRENT";
                    break;
            }

            break;
115

116
117
118
        case Hold:
            state_str = "HOLD";
            break;
119

120
121
122
        case Busy:
            state_str = "BUSY";
            break;
123

124
        case Inactive:
Emmanuel Milou's avatar
Emmanuel Milou committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

            switch (connection) {

                case Ringing:
                    (type == Incoming) ? state_str = "INCOMING":state_str = "RINGING";
                    break;

                case Connected:
                    state_str = "CURRENT";
                    break;

                default:
                    state_str = "INACTIVE";
                    break;
            }

141
            break;
142

143
        case Conferencing:
Emmanuel Milou's avatar
Emmanuel Milou committed
144
145
            state_str = "CONFERENCING";
            break;
146

147
        case Refused:
148

149
        case Error:
150

151
152
153
154
        default:
            state_str = "FAILURE";
            break;
    }
155

156
157
158
159
    return state_str;
}


160
const std::string&
161
162
Call::getLocalIp()
{
163
164
    ost::MutexLock m (_callMutex);
    return _localIPAddress;
165
166
}

167
unsigned int
168
169
Call::getLocalAudioPort()
{
170
171
    ost::MutexLock m (_callMutex);
    return _localAudioPort;
172
173
}

174
175
void
Call::setAudioStart (bool start)
176
{
177
178
    ost::MutexLock m (_callMutex);
    _audioStarted = start;
179
180
}

181
bool
182
183
Call::isAudioStarted()
{
184
185
    ost::MutexLock m (_callMutex);
    return _audioStarted;
186
187
}

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

bool
Call::setRecording()
{
    bool recordStatus = Recordable::recAudio.setRecording();

    if(!recordStatus)
      return false;

    MainBuffer *mbuffer = &(Manager::instance()._mainBuffer);

    CallID process_id = Recordable::recorder.getRecorderID();

    mbuffer->bindHalfDuplexOut(process_id, _id);
    mbuffer->bindHalfDuplexOut(process_id);
    
    Recordable::recorder.start();
  
    return recordStatus;
}