Commit 6500328a authored by llea's avatar llea

Call management

parent 2e3c8113
SFLphone (0.4)
* Reorganisation of SFLphone architecture
SFLphone (0.3.1) / 2005-04-21
* Handle error messages on screen
* Handle refused call
......
......@@ -82,7 +82,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
}
if (err < 0) {
printf ("ERROR: ALSA/snd_pcm_open: Cannot open audio device (%s)\n",
_debug ("ERROR: ALSA/snd_pcm_open: Cannot open audio device (%s)\n",
snd_strerror (err));
error->errorName(OPEN_FAILED_DEVICE, NULL);
return -1;
......@@ -95,7 +95,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
err = snd_pcm_hw_params_malloc (&hw_params);
if (err < 0) {
printf ("Cannot allocate hardware parameter structure (%s)\n",
_debug ("Cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
error->errorName(PARAMETER_STRUCT_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
......@@ -103,7 +103,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
// Init hwparams with full configuration space
if ((err = snd_pcm_hw_params_any (audio_hdl, hw_params)) < 0) {
printf ("Cannot initialize hardware parameter structure (%s)\n",
_debug ("Cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
error->errorName(PARAMETER_STRUCT_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
......@@ -112,7 +112,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
err = snd_pcm_hw_params_set_access (audio_hdl, hw_params,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) {
printf ("Cannot set access type (%s)\n", snd_strerror (err));
_debug ("Cannot set access type (%s)\n", snd_strerror (err));
error->errorName(ACCESS_TYPE_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -121,7 +121,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
err = snd_pcm_hw_params_set_format (audio_hdl, hw_params,
SND_PCM_FORMAT_S16_LE);
if (err < 0) {
printf ("Cannot set sample format (%s)\n", snd_strerror (err));
_debug ("Cannot set sample format (%s)\n", snd_strerror (err));
error->errorName(SAMPLE_FORMAT_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -134,18 +134,18 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
err = snd_pcm_hw_params_set_rate_near (audio_hdl, hw_params,
&exact_rate, 0);
if (err < 0) {
printf ("Cannot set sample rate (%s)\n", snd_strerror (err));
_debug ("Cannot set sample rate (%s)\n", snd_strerror (err));
error->errorName(SAMPLE_RATE_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
if (exact_rate != rate) {
fprintf(stderr, "The rate %d Hz is not supported by your hardware.\n ==> Using %d Hz instead.\n", rate, exact_rate);
_debug("The rate %d Hz is not supported by your hardware.\n ==> Using %d Hz instead.\n", rate, exact_rate);
}
// Set number of channels - Mono(1) or Stereo(2)
err = snd_pcm_hw_params_set_channels (audio_hdl, hw_params, MONO);
if (err < 0) {
printf ("Cannot set channel count (%s)\n", snd_strerror (err));
_debug ("Cannot set channel count (%s)\n", snd_strerror (err));
error->errorName(CHANNEL_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -153,7 +153,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
// Apply previously setup parameters
err = snd_pcm_hw_params (audio_hdl, hw_params);
if (err < 0) {
printf ("Cannot set parameters (%s)\n", snd_strerror (err));
_debug ("Cannot set parameters (%s)\n", snd_strerror (err));
error->errorName(PARAM_SETUP_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -222,19 +222,18 @@ int
AudioDriversALSA::resetDevice (void) {
int err;
printf("Resetting...\n");
_debug("Resetting...\n");
if ((err = snd_pcm_drop(audio_hdl)) < 0) {
printf ("ALSA: drop() error: %s\n", snd_strerror (err));
_debug ("ALSA: drop() error: %s\n", snd_strerror (err));
error->errorName(DROP_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
if ((err = snd_pcm_prepare(audio_hdl)) < 0) {
printf ("ALSA: prepare() error: %s\n", snd_strerror (err));
_debug ("ALSA: prepare() error: %s\n", snd_strerror (err));
error->errorName(PREPARE_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
return 0;
}
......
......@@ -50,12 +50,11 @@ AudioDriversOSS::~AudioDriversOSS (void) {
int
AudioDriversOSS::resetDevice (void) {
printf ("Resetting...");
_debug ("Resetting...\n");
if (ioctl(audio_fd, SNDCTL_DSP_RESET) < 0) {
perror("ioctl");
return -1;
}
printf ("done\n");
return 0;
}
......@@ -93,7 +92,7 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
// Fragments : No limit (0x7FFF),
int frag = ( ( 0x7FFF << 16 ) | 7 );
if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag)) {
printf ("ERROR: SETFRAG %s\n", strerror(errno));
_debug ("ERROR: SETFRAG %s\n", strerror(errno));
error->errorName(FRAGMENT_ERROR_OSS, strerror(errno));
return -1;
}
......@@ -103,37 +102,37 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
format = AFMT_S16_LE;
if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format) == -1) {
printf("ERROR: SETFMT %s\n", strerror(errno));
_debug("ERROR: SETFMT %s\n", strerror(errno));
error->errorName(SAMPLE_FORMAT_ERROR_OSS, strerror(errno));
return -1;
}
if (format != AFMT_S16_LE) {
printf ("ERROR: Format not supported\n");
_debug ("ERROR: Format not supported\n");
return -1;
}
// Setup number of channels
int channels = MONO;
if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
printf ("ERROR: DSP_STEREO %s\n", strerror(errno));
_debug ("ERROR: DSP_STEREO %s\n", strerror(errno));
error->errorName(CHANNEL_ERROR_OSS, strerror(errno));
return -1;
}
if (channels != MONO) {
printf ("ERROR: Unsupported Number of Channels\n");
_debug ("ERROR: Unsupported Number of Channels\n");
return -1;
}
// Setup sampling rate 8KHz
int rate = SAMPLING_RATE;
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate ) == -1 ) {
printf ("ERROR: DSP_SPEED %s\n", strerror(errno));
_debug ("ERROR: DSP_SPEED %s\n", strerror(errno));
error->errorName(SAMPLE_RATE_ERROR_OSS, strerror(errno));
return -1;
}
if (rate != SAMPLING_RATE) {
printf ("WARNING: driver rounded %d Hz request to %d Hz, off by %f%%\n"
_debug ("WARNING: driver rounded %d Hz request to %d Hz, off by %f%%\n"
, 8000, rate, 100*((rate-8000)/8000.0));
}
......@@ -141,13 +140,13 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
audio_buf_info info;
if (mode == WriteOnly) {
if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) == -1) {
printf ("ERROR: GETISPACE %s\n", strerror(errno));
_debug ("ERROR: GETISPACE %s\n", strerror(errno));
error->errorName(GETISPACE_ERROR_OSS, strerror(errno));
return -1;
}
} else {
if (ioctl(audio_fd, SNDCTL_DSP_GETISPACE, &info ) == -1) {
printf ("ERROR: GETOSPACE %s\n", strerror(errno));
_debug ("ERROR: GETOSPACE %s\n", strerror(errno));
error->errorName(GETOSPACE_ERROR_OSS, strerror(errno));
return -1;
}
......@@ -169,13 +168,13 @@ bool
AudioDriversOSS::openDevice (int exist_fd) {
audio_fd = exist_fd;
if (audio_fd == -1) {
printf ("ERROR: Open Failed\n");
_debug ("ERROR: Open Failed\n");
return false;
}
audio_buf_info info;
if (ioctl(audio_fd, SNDCTL_DSP_GETISPACE, &info) == -1) {
printf ("ERROR: GETISPACE %s\n", strerror(errno));
_debug ("ERROR: GETISPACE %s\n", strerror(errno));
return false;
}
// audio_buf.resize (info.fragsize * sizeof(short));
......@@ -196,11 +195,11 @@ AudioDriversOSS::readBuffer (void *ptr, int bytes) {
rc = read (audio_fd, ptr, count);
if (rc < 0) {
printf ("rc < 0 read(): %s\n", strerror(errno));
_debug ("rc < 0 read(): %s\n", strerror(errno));
}
else if (rc != count) {
printf ("WARNING: asked microphone for %d got %d\n", count, rc);
_debug ("WARNING: asked microphone for %d got %d\n", count, rc);
}
return rc;
......@@ -221,11 +220,11 @@ AudioDriversOSS::readBuffer (int bytes) {
rc = read (audio_fd, buf, count);
if (rc < 0) {
printf ("rc < 0 read(): %s\n", strerror(errno));
_debug ("rc < 0 read(): %s\n", strerror(errno));
}
else if (rc != count) {
printf ("WARNING: asked microphone for %d got %d\n", count, rc);
_debug ("WARNING: asked microphone for %d got %d\n", count, rc);
}
return rc;
......@@ -251,7 +250,7 @@ AudioDriversOSS::writeBuffer (void *ptr, int len) {
for (;;) {
int a;
if ((a = write(audio_fd, ptr, len)) < 0) {
printf ("write(): %s\n", strerror(errno));
_debug ("write(): %s\n", strerror(errno));
break;
}
if (a > 0) {
......@@ -283,7 +282,7 @@ AudioDriversOSS::writeBuffer (void) {
for (;;) {
int a;
if ((a = write(audio_fd, buf, count)) < 0) {
printf ("write(): %s\n", strerror(errno));
_debug ("write(): %s\n", strerror(errno));
break;
}
if (a > 0) {
......@@ -317,7 +316,7 @@ AudioDriversOSS::readableBytes(void) {
return 0;
}
if (ioctl (audio_fd, SNDCTL_DSP_GETISPACE, &info) == -1) {
printf ("ERROR: readableBytes %s\n", strerror(errno));
_debug ("ERROR: readableBytes %s\n", strerror(errno));
return 0;
}
......
......@@ -88,15 +88,16 @@ AudioRtp::createNewSession (SipCall *ca) {
void
AudioRtp::closeRtpSession (SipCall *ca) {
// This will make RTP threads finish.
ca->enable_audio = -1;
if (ca->enable_audio > 0) {
ca->enable_audio = -1;
if (_RTXThread != NULL) {
delete _RTXThread;
_RTXThread = NULL;
if (_RTXThread != NULL) {
delete _RTXThread;
_RTXThread = NULL;
}
// Flush audio read buffer
_manager->audiodriver->resetDevice();
}
// Flush audio read buffer
_manager->audiodriver->resetDevice();
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -208,19 +208,19 @@ ToneGenerator::buildTone (int idCountry, int idTones, int samplingRate,
*/
int
ToneGenerator::idZoneName (const string& name) {
if (name.compare("North America")) {
if (name.compare("North America") == 0) {
return ID_NORTH_AMERICA;
} else if (name.compare("France")) {
} else if (name.compare("France") == 0) {
return ID_FRANCE;
} else if (name.compare("Australia")) {
} else if (name.compare("Australia") == 0) {
return ID_AUSTRALIA;
} else if (name.compare("United Kingdom")) {
} else if (name.compare("United Kingdom") == 0) {
return ID_UNITED_KINGDOM;
} else if (name.compare("Spain")) {
} else if (name.compare("Spain") == 0) {
return ID_SPAIN;
} else if (name.compare("Italy")) {
} else if (name.compare("Italy") == 0) {
return ID_ITALY;
} else if (name.compare("Japan")) {
} else if (name.compare("Japan") == 0) {
return ID_JAPAN;
} else {
_debug("Zone no supported\n");
......
......@@ -18,7 +18,7 @@
*/
#include <iostream>
#include "audio/audiocodec.h"
//#include "audio/audiocodec.h"
#include "call.h"
#include "manager.h"
#include "sipvoiplink.h"
......@@ -104,12 +104,13 @@ Call::getVoIPLink (void)
return _voIPLink;
}
/*
void
Call::setAudioCodec (void)
{
_audiocodec = _voIPLink->getAudioCodec(getId());
}
*/
string
Call::getStatus (void)
{
......@@ -185,7 +186,7 @@ Call::setType (enum CallType type)
bool
Call::isBusy (void)
{
if (isAnswered() or isOffHold() or isOnMute()) {
if (isAnswered() or isOffHold() or isOnMute() or isOffMute()) {
return true;
} else {
return false;
......@@ -209,6 +210,12 @@ Call::isOnMute (void)
return (_state == MuteOn) ? true : false;
}
bool
Call::isOffMute (void)
{
return (_state == MuteOff) ? true : false;
}
bool
Call::isTransfered (void)
{
......@@ -274,35 +281,35 @@ Call::hangup (void)
{
int i = _voIPLink->hangup(_id);
_voIPLink->deleteSipCall(_id);
return 1;
return i;
}
int
Call::answer (void)
{
int i = _voIPLink->answer(_id);
return 1;
return i;
}
int
Call::onHold (void)
{
int i = _voIPLink->onhold(_id);
return 1;
return i;
}
int
Call::offHold (void)
{
int i = _voIPLink->offhold(_id);
return 1;
return i;
}
int
Call::transfer (const string& to)
{
int i = _voIPLink->transfer(_id, to);
return 1;
return i;
}
int
......@@ -322,7 +329,7 @@ Call::refuse (void)
{
int i = _voIPLink->refuse(_id);
_voIPLink->deleteSipCall(_id);
return 1;
return i;
}
int
......@@ -330,7 +337,7 @@ Call::cancel (void)
{
int i = _voIPLink->cancel(_id);
_voIPLink->deleteSipCall(_id);
return 1;
return i;
}
///////////////////////////////////////////////////////////////////////////////
......@@ -343,5 +350,5 @@ Call::initConstructor(void)
_state = NotExist;
_type = Null;
_voIPLinkId = 1;
_audiocodec = NULL;
// _audiocodec = NULL;
}
......@@ -52,7 +52,7 @@ enum CallType {
#include "manager.h"
class AudioCodec;
//class AudioCodec;
class Call {
public:
......@@ -71,7 +71,7 @@ public:
void setVoIPLinkId (short voIPLinkId);
void setVoIPLink (VoIPLink* voIPLink);
VoIPLink* getVoIPLink(void);
void setAudioCodec(void);
// void setAudioCodec(void);
string getStatus (void);
void setStatus (const string& status);
......@@ -93,6 +93,7 @@ public:
bool isOnHold (void);
bool isOffHold (void);
bool isOnMute (void);
bool isOffMute (void);
bool isTransfered (void);
bool isHungup (void);
bool isRinging (void);
......@@ -120,7 +121,7 @@ private:
Manager* _manager;
VoIPLink* _voIPLink;
AudioCodec* _audiocodec;
// AudioCodec* _audiocodec;
short _id;
short _voIPLinkId;
......
/****************************************************************************
** Form implementation generated from reading ui file 'gui/qt/configurationpanel.ui'
**
** Created: Fri May 20 14:27:25 2005
** Created: Tue May 24 16:49:53 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** Form interface generated from reading ui file 'gui/qt/configurationpanel.ui'
**
** Created: Fri May 20 14:27:25 2005
** Created: Tue May 24 16:49:53 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** Form implementation generated from reading ui file 'gui/qt/phonebook.ui'
**
** Created: Fri May 20 14:27:25 2005
** Created: Tue May 24 16:49:52 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** Form interface generated from reading ui file 'gui/qt/phonebook.ui'
**
** Created: Fri May 20 14:27:25 2005
** Created: Tue May 24 16:49:52 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
......@@ -130,7 +130,7 @@ QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, const char *name, WFlags f,
Qt::WStyle_NoBorder);
_currentLine = -1;
_chosenLine = -1;
_freeLine = -1;
_prevLine = -1;
_first = true;
_chooseLine = false;
_transfer = false;
......@@ -590,7 +590,7 @@ QtGUIMainWindow::changeLineStatePixmap (int line, line_state state)
if (state == ONHOLD) {
// Because for the state of line pixmap there are just 2 states
// (FREE and BUSY), so we associate ONHOLD to BUSY
state = state - 1;
state = BUSY;
}
phLines[line]->button()->setPixmap(TabLinePixmap[line][state]);
}
......@@ -612,6 +612,7 @@ QtGUIMainWindow::putOnHoldBusyLine (int line)
{
if (line != -1 and !phLines[line]->getbRinging()) {
// Occurs when newly off-hook line replaces another one.
_debug("On hold line %d [id=%d]\n", line, line2id(line));
qt_onHoldCall(line2id(line));
changeLineStatePixmap(line, ONHOLD);
return 1;
......@@ -749,15 +750,18 @@ QtGUIMainWindow::peerHungupCall (short id)
{
int line = id2line(id);
if (line == getCurrentLine()) {
stopCallTimer(id);
_callmanager->displayStatus(HUNGUP_STATUS);
setCurrentLine(-1);
}
getPhoneLine(id)->setStatus(QString(getCall(id)->getStatus()));
changeLineStatePixmap(line, FREE);
stopCallTimer(id);
getPhoneLine(id)->setbRinging(false);
getPhoneLine(id)->setCallId(0);
setChooseLine(false);
setCurrentLine(-1);
_TabIncomingCalls[line] = -1;
return 1;
}
......@@ -827,6 +831,7 @@ QtGUIMainWindow::qt_outgoingCall (void)
id = outgoingCall(to);
if (id > 0) {
line = associateCall2Line(id);
_debug("Call %d -> line %d\n", id, line);
setCurrentLine(line);
displayStatus(TRYING_STATUS);
......@@ -961,7 +966,6 @@ QtGUIMainWindow::toggleLine (int line)
busyLine = busyLineNumber();
id = line2id(line);
_debug("line2id(line) = %d and busy line = %d\n", id, busyLine);
if (id > 0) {
// If the call-id already exists
call = getCall(id);
......@@ -1007,11 +1011,13 @@ QtGUIMainWindow::toggleLine (int line)
setChosenLine(line);
putOnHoldBusyLine(busyLine);
if (getFreeLine() != -1 and getFreeLine() != line) {
changeLineStatePixmap(getFreeLine(), FREE);
if (getPrevLine() != -1 and getPrevLine() != line
and phLines[getPrevLine()]->isFree()) {
changeLineStatePixmap(getPrevLine(), FREE);
}
setFreeLine(line);
setPrevLine(line);
_lcd->setInFunction(false);
_lcd->clearBuffer();
dialtone(true);
......@@ -1136,6 +1142,7 @@ QtGUIMainWindow::volumeMicChanged (int val) {
void
QtGUIMainWindow::registerSlot (void) {
_panel->saveSlot();
registerVoIPLink();
}
......@@ -1335,7 +1342,6 @@ QtGUIMainWindow::blinkRingSlot (void)
{
static bool isOn = false;
int state = BUSY;
int line;
int i;
if (isThereIncomingCall() != -1) {
......
......@@ -277,9 +277,9 @@ private:
// line by the user
bool _chooseLine;
int _chosenLine;
int _freeLine;
inline void setFreeLine(int line) { _freeLine = line; }
inline int getFreeLine(void) { return _freeLine; }
int _prevLine;
inline void setPrevLine(int line) { _prevLine = line; }
inline int getPrevLine(void) { return _prevLine; }
// Array of incoming calls
int _TabIncomingCalls[NUMBER_OF_LINES];
......
/****************************************************************************
** Form implementation generated from reading ui file 'gui/qt/url_input.ui'
**
** Created: Fri May 20 14:27:25 2005
** Created: Tue May 24 16:49:53 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** Form interface generated from reading ui file 'gui/qt/url_input.ui'
**
** Created: Fri May 20 14:27:25 2005
** Created: Tue May 24 16:49:52 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
......@@ -100,6 +100,11 @@ Manager::~Manager (void)
delete _voIPLinkVector;
delete _error;
delete _tone;
delete _codecDescVector;
delete audiodriver;