call.cpp 3.37 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
20
 *  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.
 */
#include "call.h"
21
#include "manager.h"
jpbl's avatar
jpbl committed
22

Yun Liu's avatar
Yun Liu committed
23
24
25
26
27
28
29
30
31
32
Call::Call(const CallID& id, Call::CallType type)
           : _callMutex()
           , _audioStarted(false)    
           , _localIPAddress("") 
           , _localAudioPort(0)
           , _localExternalAudioPort(0)
           , _id(id) 
           , _type(type) 
           , _connectionState(Call::Disconnected)
           , _callState(Call::Inactive)
Emmanuel Milou's avatar
Emmanuel Milou committed
33
           , _callConfig (Call::Classic)
Yun Liu's avatar
Yun Liu committed
34
35
           , _peerName()
           , _peerNumber()
jpbl's avatar
jpbl committed
36
{
37
38
39
 
    FILE_TYPE fileType = FILE_WAV;
    SOUND_FORMAT soundFormat = INT16;
40

Alexandre Savard's avatar
Alexandre Savard committed
41
    recAudio.setRecordingOption(fileType,soundFormat,44100, Manager::instance().getConfigString (AUDIO, RECORD_PATH),id);
42
    // _debug("CALL::Constructor for this clss is called \n");    
jpbl's avatar
jpbl committed
43
44
45
}


yanmorin's avatar
   
yanmorin committed
46
Call::~Call()
jpbl's avatar
jpbl committed
47
{
48
   // _debug("CALL::~Call(): Destructor for this clss is called \n");
49
50
   
   if(recAudio.isOpenFile()) {
51
     // _debug("CALL::~Call(): A recording file is open, close it \n");
52
53
     recAudio.closeFile();
   }
jpbl's avatar
jpbl committed
54
55
56
}

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

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


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

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

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
std::string
Call::getStateStr (CallState state)
{
    std::string state_str;
        
    switch (state) {
        case Active:
            state_str = "CURRENT";
            break;
        case Hold:
            state_str = "HOLD";
            break;
        case Busy:
            state_str = "BUSY";
            break;
        case Refused:
        case Error:
        case Inactive:
        default:
            state_str = "FAILURE";
            break;
    }
    return state_str;
}


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
const std::string& 
Call::getLocalIp()
{
  ost::MutexLock m(_callMutex);  
  return _localIPAddress;
}

unsigned int 
Call::getLocalAudioPort()
{
  ost::MutexLock m(_callMutex);  
  return _localAudioPort;
}

void 
Call::setAudioStart(bool start)
{
  ost::MutexLock m(_callMutex);  
  _audioStarted = start;  
}

bool 
Call::isAudioStarted()
{
  ost::MutexLock m(_callMutex);  
  return _audioStarted;
}

139
140
141
142
143
void
Call::setRecording()
{
  recAudio.setRecording();
}
alexandresavard's avatar
alexandresavard committed
144

145
146
147
148
149
void 
Call::initRecFileName() {
  recAudio.initFileName(_peerNumber);
}

150
151
152
153
154
155
void
Call::stopRecording()
{
  recAudio.stopRecording();
}

alexandresavard's avatar
alexandresavard committed
156
157
158
159
160
161
bool
Call::isRecording()
{
  return recAudio.isRecording();
}