Commit 07cce3bb authored by llea's avatar llea
Browse files

Management of lines

parent bf99cb74
SFLphone (0.3.1) / 2005-04-21
* Handle error messages on screen
* Handle refused call
* Notification of remote RINGING event added
* Management of lines updated
SFLphone (0.3) / 2005-04-05
* ALSA driver support added
* GSM audio codec support added
* Rings support (just ulaw format) added
* Ringtones support (just ulaw format) added
* Notification incoming call added
* Apply skin feature added
* Volume control added
......
......@@ -66,8 +66,8 @@ public:
void *data;
private:
size_t size;
size_t realsize;
size_t size;
};
#endif // __AUDIOBUFFER_H__
......@@ -169,4 +169,24 @@ AudioCodec::gsmDestroy (void) {
gsm_destroy(encode_gsmhandle);
}
void
AudioCodec::create (int pt) {
switch (pt) {
case PAYLOAD_CODEC_GSM:
AudioCodec::gsmCreate();
break;
default:
break;
}
}
void
AudioCodec::destroy (int pt) {
switch (pt) {
case PAYLOAD_CODEC_GSM:
AudioCodec::gsmDestroy();
break;
default:
break;
}
}
......@@ -54,6 +54,10 @@ public:
void noSupportedCodec (void);
static int codecDecode (int, short *, unsigned char *, unsigned int);
static int codecEncode (int, unsigned char *, short *, unsigned int);
static void create (int);
static void destroy (int);
private:
static void gsmCreate (void);
static void gsmDestroy (void);
};
......
......@@ -25,7 +25,6 @@
AudioDrivers::AudioDrivers (void) {
this->devstate = AudioDrivers::DeviceClosed;
}
AudioDrivers::~AudioDrivers (void) {
......
......@@ -29,6 +29,7 @@ class AudioDrivers {
public:
AudioDrivers (void);
virtual ~AudioDrivers (void);
AudioBuffer audio_buf; // Buffer that the application fills
enum DeviceState {
DeviceOpened,
......@@ -46,7 +47,6 @@ public:
virtual int readBuffer (int) = 0;
virtual unsigned int readableBytes (void) = 0;
AudioBuffer audio_buf; // Buffer that the application fills
protected:
DeviceState devstate; // Current state
......
......@@ -93,7 +93,6 @@ AudioRtp::closeRtpSession (SipCall *ca) {
ca->enable_audio = -1;
if (RTXThread != NULL) {
qDebug("RTXThread DELETED");
delete RTXThread;
RTXThread = NULL;
}
......@@ -107,6 +106,7 @@ AudioRtp::closeRtpSession (SipCall *ca) {
////////////////////////////////////////////////////////////////////////////////
AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioDrivers *driver,
AudioDrivers *read_driver, Manager *mngr, bool sym) {
this->time = new Time();
this->manager = mngr;
this->ca = sipcall;
this->sym =sym;
......@@ -128,12 +128,10 @@ AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioDrivers *driver,
qDebug("Forced port %d", forcedPort);
session = new SymmetricRTPSession (local_ip, forcedPort);
}
AudioCodec::gsmCreate();
}
AudioRtpRTX::~AudioRtpRTX () {
this->terminate();
AudioCodec::gsmDestroy();
if (!sym) {
if (sessionRecv != NULL) {
......@@ -163,7 +161,7 @@ AudioRtpRTX::run (void) {
timestamp;
int expandedSize;
short *data_for_speakers = NULL;
int countTime = 0;
unsigned int countTime = 0;
data_for_speakers = new short[2048];
data_from_mic = new short[1024];
data_from_mic_tmp = new short[1024];
......@@ -255,6 +253,8 @@ AudioRtpRTX::run (void) {
session->startRunning();
}
AudioCodec::create(ca->payload);
while (ca->enable_audio != -1) {
////////////////////////////
// Send session
......@@ -328,9 +328,9 @@ AudioRtpRTX::run (void) {
manager->getSpkrVolume());
// Notify (with a bip) an incoming call when there is already a call
countTime += TimerPort::getElapsed();
countTime += time->getSecond();
if (manager->getNumberPendingCalls() != 1 and manager->ringing()) {
if ((countTime % 2000) <= 10 and (countTime % 2000) >= 0) {
if ((countTime % 2000) <= 10 and (countTime % 2000) > 0) {
manager->notificationIncomingCall();
}
}
......@@ -345,6 +345,7 @@ AudioRtpRTX::run (void) {
TimerPort::incTimer(frameSize); // 'frameSize' ms
}
AudioCodec::destroy(ca->payload);
delete[] data_for_speakers;
delete[] data_from_mic;
delete[] data_from_mic_tmp;
......
......@@ -23,6 +23,7 @@
#include <cstdlib>
#include <ccrtp/rtp.h>
#include <cc++/numbers.h>
using namespace ost;
......@@ -40,6 +41,7 @@ class AudioRtpRTX : public Thread, public TimerPort {
public:
AudioRtpRTX (SipCall *, AudioDrivers *, AudioDrivers *, Manager *, bool);
~AudioRtpRTX();
Time *time; // For incoming call notification
virtual void run ();
private:
......
This diff is collapsed.
This diff is collapsed.
/****************************************************************************
** Form interface generated from reading ui file 'configurationpanel.ui'
**
** Created: Tue Apr 12 09:35:08 2005
** Created: Wed Apr 20 14:48:03 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......@@ -120,8 +120,8 @@ public:
QLabel* textLabel2_2;
QLabel* pixmapLabel1;
QWidget* CodecsPage_4;
QLabel* pixmapLabel2;
QLabel* textLabel1;
QLabel* pixmapLabel2;
public slots:
virtual void saveSlot();
......
......@@ -59,6 +59,7 @@ Manager::Manager (QString *Dc = NULL) {
exist = createSettingsPath();
selectAudioDriver();
phonegui = new QtGUIMainWindow (0, 0 ,
Qt::WDestructiveClose |
Qt::WStyle_Customize |
......@@ -70,7 +71,6 @@ Manager::Manager (QString *Dc = NULL) {
error = new Error(this);
sip_init();
selectAudioDriver();
// Init variables
b_ringing = false;
......@@ -142,7 +142,7 @@ Manager::createSettingsPath (void) {
void
Manager::selectAudioDriver (void) {
if (Config::getb("Audio", "Drivers.driverOSS")) {
useAlsa = false;
useAlsa = false;
this->audiodriver = new AudioDriversOSS (AudioDrivers::ReadWrite, error);
}
if (Config::getb("Audio", "Drivers.driverALSA")) {
......@@ -198,14 +198,27 @@ Manager::ringing (void) {
// When IP-phone user receives a call
void
Manager::ring (bool var) {
if (sip->getNumberPendingCalls() != 1 and tonezone == true
and var == false) {
// If more than one line is ringing
for (int i = 0; i < NUMBER_OF_LINES; i++) {
if (i != getCurrentLineNumber() and phLines[i]->getbRinging()) {
tonezone = false;
tone->playRingtone ((gui()->getRingFile()).ascii());
}
}
}
if (this->b_ringing != var) {
this->b_ringing = var;
}
tonezone = ringing();
if (sip->getNumberPendingCalls() == 1)
if (sip->getNumberPendingCalls() == 1) {
// If just one line is ringing
tone->playRingtone ((gui()->getRingFile()).ascii());
}
}
// When IP-phone user makes call
......@@ -220,11 +233,15 @@ Manager::ringTone (bool var) {
void
Manager::congestion (bool var) {
if (this->b_congestion != var) {
this->b_congestion = var;
if (error->getError() == 0) {
if (this->b_congestion != var) {
this->b_congestion = var;
}
tonezone = var;
tone->toneHandle(ZT_TONE_CONGESTION);
} else {
error->errorName(DEVICE_NOT_OPEN, NULL);
}
tonezone = var;
tone->toneHandle(ZT_TONE_CONGESTION);
}
void
......@@ -267,16 +284,16 @@ Manager::actionHandle (int lineNumber, int action) {
sip->manageActions (lineNumber, REFUSE_CALL);
this->ring(false);
phLines[lineNumber]->setbRinging(false);
gui()->lcd->setStatus("Call refused");
gui()->lcd->setStatus(REFUSED_CALL_STATUS);
break;
case ANSWER_CALL:
// TODO
// Stopper l'etat "ringing" du main (audio, signalisation, gui)
sip->manageActions (lineNumber, ANSWER_CALL);
this->ring(false);
sip->manageActions (lineNumber, ANSWER_CALL);
phLines[lineNumber]->setbRinging(false);
gui()->lcd->setStatus("Connected");
gui()->lcd->setStatus(CONNECTED_STATUS);
gui()->startCallTimer(lineNumber);
break;
......@@ -292,7 +309,6 @@ Manager::actionHandle (int lineNumber, int action) {
case ONHOLD_CALL:
if (sip->call[lineNumber] != NULL) {
//gui()->lcd->setStatus(ONHOLD_STATUS);
sip->manageActions (lineNumber, ONHOLD_CALL);
}
break;
......@@ -341,6 +357,19 @@ Manager::isNotUsedLine (int line) {
return false;
}
bool
Manager::isUsedLine (int line) {
for (int k = 0; k < NUMBER_OF_LINES; k++) {
if (line == k) {
if (sip->call[line] != NULL) {
return true;
}
}
}
return false;
}
int
Manager::findLineNumberNotUsed (void) {
return sip->findLineNumberNotUsed();
......@@ -363,26 +392,33 @@ Manager::handleRemoteEvent (int code, char * reason, int remotetype, int line) {
switch (remotetype) {
// Registration success
case EXOSIP_REGISTRATION_SUCCESS:
gui()->lcd->setStatus("Logged in");
case EXOSIP_REGISTRATION_SUCCESS:
gui()->lcd->setStatus(LOGGED_IN_STATUS);
break;
// Registration failure
case EXOSIP_REGISTRATION_FAILURE:
gui()->lcd->setStatus("Registration failure");
gui()->lcd->setStatus(REG_FAIL_STATUS);
break;
// Remote callee answered
case EXOSIP_CALL_ANSWERED:
if (!gui()->transfer)
gui()->lcd->setStatus("Connected");
// Start call timer
gui()->startCallTimer(gui()->currentLineNumber);
gui()->lcd->setStatus(CONNECTED_STATUS);
// Start call timer
gui()->startCallTimer(getCurrentLineNumber());
phLines[getCurrentLineNumber()]->setbDial(false);
break;
// Remote callee hangup
case EXOSIP_CALL_CLOSED:
//if (getCallInProgress()) {
if (sip->getNumberPendingCalls() == 0
or !phLines[line]->isOnHold()) {
// Show HUNGUP_STATUS if there's not pending call
// or line is not onhold
gui()->lcd->clear(QString(HUNGUP_STATUS));
}
if (phLines[line]->getbInProgress()) {
this->ring(false);
phLines[line]->setbRinging(false);
......@@ -398,13 +434,14 @@ Manager::handleRemoteEvent (int code, char * reason, int remotetype, int line) {
gui()->setCurrentLineNumber(-1);
}
phLines[line]->setbDial(false);
gui()->lcd->clear(QString("Hung up"));
sip->notUsedLine = -1;
break;
// Remote call ringing
case EXOSIP_CALL_RINGING:
gui()->lcd->setStatus("Ringing");
gui()->lcd->setStatus(RINGING_STATUS);
phLines[getCurrentLineNumber()]->setbDial(false);
break;
default:
......@@ -413,13 +450,13 @@ Manager::handleRemoteEvent (int code, char * reason, int remotetype, int line) {
// If dialog is established
if (code == 101) {
gui()->lcd->setStatus("Ringing");
gui()->lcd->setStatus(RINGING_STATUS);
// if error code
} else {
if (code == 407) {
gui()->lcd->setStatus("Trying...");
} else if (code > 399 and code != 407) {
if (code == AUTH_REQUIRED) {
gui()->lcd->setStatus(TRYING_STATUS);
} else if (code > 399 and code != AUTH_REQUIRED and
code != REQ_TERMINATED) {
qinfo = QString::number(code, 10) + " " +
QString(reason);
gui()->lcd->setStatus(qinfo);
......@@ -427,6 +464,22 @@ Manager::handleRemoteEvent (int code, char * reason, int remotetype, int line) {
qinfo = QString(reason);
}
}
// Store the status of current line
if(getCurrentLineNumber() != -1) {
phLines[getCurrentLineNumber()]->status = getStatusRender();
//qDebug("line[%d] status: %s", getCurrentLineNumber(),
// (phLines[getCurrentLineNumber()]->status).ascii());
}
}
bool
Manager::tryingState (int line) {
if (phLines[line]->status == TRYING_STATUS) {
return true;
} else {
return false;
}
}
void
......@@ -449,6 +502,11 @@ Manager::bufferTextRender (void) {
return QString(*gui()->lcd->textBuffer);
}
QString
Manager::getStatusRender (void) {
return (gui()->lcd->getStatus());
}
void
Manager::getInfoStun (StunAddress4& stunSvrAddr) {
StunAddress4 mappedAddr;
......@@ -487,12 +545,13 @@ Manager::getFirewallAddress (void) {
}
/**
* Returs true if the current line replaces another one
* Returns true if the current line replaces another one
*/
bool
Manager::otherLine (void) {
if (gui()->busyNum != -1) {
if (gui()->busyNum != gui()->currentLineNumber) {
if (phLines[getCurrentLineNumber()]->status != TRYING_STATUS and
gui()->busyNum != getCurrentLineNumber()) {
return true;
}
}
......
......@@ -24,6 +24,17 @@
#include "phoneline.h"
#include "../stund/stun.h"
// Status list
#define LOGGED_IN_STATUS "Logged in"
#define REG_FAIL_STATUS "Registration failure"
#define CONNECTED_STATUS "Connected"
#define HUNGUP_STATUS "Hung up"
#define RINGING_STATUS "Ringing"
#define TRYING_STATUS "Trying..."
#define REFUSED_CALL_STATUS "Refused call"
#define ENTER_NUMBER_STATUS "Enter Phone Number:"
#define TRANSFER_STATUS "Transfer to:"
#include <string>
using namespace std;
......@@ -73,7 +84,9 @@ public:
void closeSound (SipCall *);
void selectAudioDriver (void);
QString bufferTextRender (void);
QString getStatusRender (void);
bool isNotUsedLine (int);
bool isUsedLine (int);
bool isRingingLine (int);
int newCallLineNumber (void);
void getInfoStun (StunAddress4 &);
......@@ -96,13 +109,15 @@ public:
void ringTone (bool);
void startDialTone (void);
void congestion (bool);
inline bool getbCongestion (void) { return b_congestion; }
void notificationIncomingCall(void);
void errorDisplay (char*);
void nameDisplay (char*);
void spkrSoundVolume (int);
void micSoundVolume (int);
inline int getSpkrVolume (void) { return spkr_volume; }
inline int getMicVolume (void) { return mic_volume; }
inline int getSpkrVolume (void) { return spkr_volume; }
inline int getMicVolume (void) { return mic_volume; }
bool tryingState (int);
private:
bool exist;
......
/****************************************************************************
** Form implementation generated from reading ui file 'phonebook.ui'
**
** Created: Tue Apr 12 09:35:07 2005
** Created: Wed Apr 20 14:48:03 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** Form interface generated from reading ui file 'phonebook.ui'
**
** Created: Tue Apr 12 09:35:07 2005
** Created: Wed Apr 20 14:48:03 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
......@@ -71,9 +71,12 @@ private:
JPushButton *jpb;
enum line_state state;
enum line_state stateLine;
bool b_dial;
bool b_inProgress;
bool b_ringing;
bool b_dial; // if ok button is clicked (->true)
bool b_inProgress; // if outgoing call,
// before remote callee answers (->true)
bool b_ringing; // if incoming call,
// before IP-phone user answers (->true)
};
#endif // __PHONE_LINE_H__
......@@ -526,12 +526,15 @@ QtGUIMainWindow::numLineBusy(void) {
void
QtGUIMainWindow::dialTone (bool var) {
if (this->b_dialtone != var) {
this->b_dialtone = var;
if (callmanager->error->getError() == 0) {
if (this->b_dialtone != var) {
this->b_dialtone = var;
}
callmanager->tonezone = var;
callmanager->tone->toneHandle(ZT_TONE_DIALTONE);
} else {
callmanager->error->errorName(DEVICE_NOT_OPEN, NULL);
}
callmanager->tonezone = var;
callmanager->tone->toneHandle(ZT_TONE_DIALTONE);
}
///////////////////////////////////////////////////////////////////////////////
// Public Methods implementations //
......@@ -572,7 +575,7 @@ QtGUIMainWindow::toggleLine (int num_line) {
if (callmanager->isNotUsedLine(currentLineNumber) and busyNum == -1) {
qDebug("GUI: FIRST LINE IN USED %d", currentLineNumber);
lcd->setStatus("Enter Phone Number:");
lcd->setStatus(ENTER_NUMBER_STATUS);
chosenLine = currentLineNumber;
if (!noChoose) {
choose = true;
......@@ -587,7 +590,7 @@ QtGUIMainWindow::toggleLine (int num_line) {
if (busyNum != currentLineNumber && busyNum != -1) {
if (callmanager->isNotUsedLine(currentLineNumber)) {
qDebug("GUI: Line %d replaces another one", currentLineNumber);
lcd->clear(QString("Enter Phone Number:"));
lcd->clear(QString(ENTER_NUMBER_STATUS));
chosenLine = currentLineNumber;
lcd->inFunction = false;
if (!noChoose) {
......@@ -599,10 +602,19 @@ QtGUIMainWindow::toggleLine (int num_line) {
callmanager->phLines[busyNum]->setStateLine(ONHOLD);
callmanager->actionHandle (busyNum, ONHOLD_CALL);
if (!callmanager->phLines[currentLineNumber]->getbDial()) {
if (callmanager->sip->call[busyNum] == NULL) {
// If ok-button not clicked before
if (callmanager->sip->call[busyNum] == NULL and
!callmanager->tryingState(busyNum)) {
setInactiveLine(busyNum);
}
this->dialTone(true);
callmanager->phLines[busyNum]->setbDial(false);
if (!callmanager->phLines[currentLineNumber]->getbRinging()
and callmanager->sip->call[currentLineNumber] == NULL and
!callmanager->tryingState(currentLineNumber)) {
// If no occured incoming call (not ringing and call[current]=null)
this->dialTone(true);
}
}
callmanager->phLines[currentLineNumber]->setState(BUSY);
qDebug("GUI: state ON-HOLD line busyNum %d", busyNum);
......@@ -615,38 +627,53 @@ QtGUIMainWindow::toggleLine (int num_line) {
callmanager->phLines[currentLineNumber]->button()->setPixmap(
TabLinePixmap[currentLineNumber][BUSY]);
callmanager->phLines[currentLineNumber]->setState(BUSY);
// Answer new call
if (callmanager->isRingingLine(currentLineNumber) and
if ((callmanager->isRingingLine(currentLineNumber) ||
(callmanager->isUsedLine(currentLineNumber) and
callmanager->phLines[currentLineNumber]->getbRinging())) and
callmanager->phLines[currentLineNumber]->getStateLine() != ONHOLD){
qDebug("GUI: -- New answered call %d --", currentLineNumber);
callmanager->actionHandle (currentLineNumber, ANSWER_CALL);
callmanager->phLines[currentLineNumber]->setState(BUSY);
callmanager->phLines[currentLineNumber]->setStateLine(BUSY);
lcd->clearBuffer();
lcd->appendText(callmanager->phLines[currentLineNumber]->text);
}
else if (callmanager->phLines[currentLineNumber]->getStateLine()
== ONHOLD) {
== ONHOLD
or callmanager->tryingState(currentLineNumber)) {
qDebug("GUI: state OFF-HOLD line %d", currentLineNumber);
lcd->clear(QString("Connected"));
lcd->clear(QString(CONNECTED_STATUS));
if (callmanager->sip->call[currentLineNumber] != NULL) {
lcd->inFunction = true;
if (!callmanager->phLines[currentLineNumber]->getbInProgress()){
// Timer-call function
lcd->inFunction = true;
} else {
// Time function
lcd->inFunction = false;
}
}
callmanager->phLines[currentLineNumber]->setStateLine(OFFHOLD);
callmanager->actionHandle (currentLineNumber, OFFHOLD_CALL);
lcd->appendText(callmanager->phLines[currentLineNumber]->text);
lcd->setStatus(callmanager->phLines[currentLineNumber]->status);
}
}
else if (callmanager->phLines[currentLineNumber]->isOnHold()){
// Change state to ONHOLD
callmanager->phLines[currentLineNumber]->setState(ONHOLD);
callmanager->phLines[currentLineNumber]->setStateLine(ONHOLD);
// Change status to ONHOLD
qDebug("GUI: state ON-HOLD line %d", currentLineNumber);
lcd->setStatus(ONHOLD_STATUS);
callmanager->actionHandle (currentLineNumber, ONHOLD_CALL);
if (callmanager->sip->call[currentLineNumber] == NULL) {