call.cpp 3.86 KB
Newer Older
yanmorin's avatar
   
yanmorin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 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
const char * const Call::DEFAULT_ID = "audiolayer_id";

37
Call::Call (const std::string& id, Call::CallType type)
38
39
40
41
42
43
44
45
46
47
48
    : _callMutex()
    , _localIPAddress ("")
    , _localAudioPort (0)
    , _id (id)
    , _confID ("")
    , _type (type)
    , _connectionState (Call::Disconnected)
    , _callState (Call::Inactive)
    , _callConfig (Call::Classic)
    , _peerName()
    , _peerNumber()
Julien Bonjean's avatar
Julien Bonjean committed
49
{
50

jpbl's avatar
jpbl committed
51
52
53
}


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

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

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


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

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

87
std::string
Julien Bonjean's avatar
Julien Bonjean committed
88
89
Call::getStateStr ()
{
Rafaël Carré's avatar
Rafaël Carré committed
90
    switch (getState()) {
91
    case Active:
Rafaël Carré's avatar
Rafaël Carré committed
92
93
        switch (getConnectionState()) {
        case Ringing: 	return isIncoming() ? "INCOMING" : "RINGING";
94
        case Connected:
Rafaël Carré's avatar
Rafaël Carré committed
95
        default:		return isRecording() ? "RECORD" : "CURRENT";
96
        }
Rafaël Carré's avatar
Rafaël Carré committed
97
98
    case Hold:			return "HOLD";
    case Busy:			return "BUSY";
99
    case Inactive:
Rafaël Carré's avatar
Rafaël Carré committed
100
101
102
103
    	switch (getConnectionState()) {
    	case Ringing:	return isIncoming() ? "INCOMING" : "RINGING";
    	case Connected:	return "CURRENT";
    	default:		return "INACTIVE";
104
    	}
Rafaël Carré's avatar
Rafaël Carré committed
105
    case Conferencing:	return "CONFERENCING";
106
107
    case Refused:
    case Error:
Rafaël Carré's avatar
Rafaël Carré committed
108
    default:			return "FAILURE";
109
110
111
112
    }
}


113
const std::string&
Julien Bonjean's avatar
Julien Bonjean committed
114
115
Call::getLocalIp()
{
116
117
    ost::MutexLock m (_callMutex);
    return _localIPAddress;
118
119
}

120
unsigned int
Julien Bonjean's avatar
Julien Bonjean committed
121
122
Call::getLocalAudioPort()
{
123
124
    ost::MutexLock m (_callMutex);
    return _localAudioPort;
125
126
}

127
bool
Julien Bonjean's avatar
Julien Bonjean committed
128
129
Call::setRecording()
{
130
    bool recordStatus = Recordable::recAudio.isRecording();
131

132
    Recordable::recAudio.setRecording();
Rafaël Carré's avatar
Rafaël Carré committed
133
134
    MainBuffer *mbuffer = Manager::instance().getMainBuffer();
    std::string process_id = Recordable::recorder.getRecorderID();
135

Emmanuel Milou's avatar
Emmanuel Milou committed
136
137
138
    if (!recordStatus) {
        mbuffer->bindHalfDuplexOut (process_id, _id);
        mbuffer->bindHalfDuplexOut (process_id);
139

140
        Recordable::recorder.start();
Rafaël Carré's avatar
Rafaël Carré committed
141
    } else {
Emmanuel Milou's avatar
Emmanuel Milou committed
142
143
        mbuffer->unBindHalfDuplexOut (process_id, _id);
        mbuffer->unBindHalfDuplexOut (process_id);
144
145
146
    }

    Manager::instance().getMainBuffer()->stateInfo();
147
148
149

    return recordStatus;
}