Commit 25beb37d authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6905: simplify SIP code

try to make it more readable/understandable
parent 7c87bca1
...@@ -70,7 +70,6 @@ static const char *const CONFIG_ACCOUNT_TYPE = "Account.type"; ...@@ -70,7 +70,6 @@ static const char *const CONFIG_ACCOUNT_TYPE = "Account.type";
static const char *const CONFIG_ACCOUNT_ALIAS = "Account.alias"; static const char *const CONFIG_ACCOUNT_ALIAS = "Account.alias";
static const char *const CONFIG_ACCOUNT_MAILBOX = "Account.mailbox"; static const char *const CONFIG_ACCOUNT_MAILBOX = "Account.mailbox";
static const char *const CONFIG_ACCOUNT_ENABLE = "Account.enable"; static const char *const CONFIG_ACCOUNT_ENABLE = "Account.enable";
static const char *const CONFIG_ACCOUNT_RESOLVE_ONCE = "Account.resolveOnce";
static const char *const CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.expire"; static const char *const CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.expire";
static const char *const CONFIG_CREDENTIAL_NUMBER = "Credential.count"; static const char *const CONFIG_CREDENTIAL_NUMBER = "Credential.count";
static const char *const ACCOUNT_DTMF_TYPE = "Account.dtmfType"; static const char *const ACCOUNT_DTMF_TYPE = "Account.dtmfType";
......
...@@ -248,5 +248,3 @@ void AudioRtpFactory::sendDtmfDigit (int digit) ...@@ -248,5 +248,3 @@ void AudioRtpFactory::sendDtmfDigit (int digit)
} }
} }
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "AudioRtpRecordHandler.h" #include "AudioRtpRecordHandler.h"
#include <fstream> #include <fstream>
#include "sip/sipcall.h"
#include "audio/audiolayer.h" #include "audio/audiolayer.h"
#include "manager.h" #include "manager.h"
......
...@@ -36,7 +36,7 @@ using std::ptrdiff_t; ...@@ -36,7 +36,7 @@ using std::ptrdiff_t;
#include <ccrtp/rtp.h> #include <ccrtp/rtp.h>
#include <list> #include <list>
#include "sip/sipcall.h" class SIPCall;
#include "audio/codecs/audiocodec.h" #include "audio/codecs/audiocodec.h"
#include "audio/samplerateconverter.h" #include "audio/samplerateconverter.h"
#include "audio/noisesuppress.h" #include "audio/noisesuppress.h"
...@@ -105,7 +105,7 @@ class AudioRtpRecord ...@@ -105,7 +105,7 @@ class AudioRtpRecord
class AudioRtpRecordHandler class AudioRtpRecordHandler
{ {
public: public:
AudioRtpRecordHandler (SIPCall *ca); AudioRtpRecordHandler(SIPCall *);
virtual ~AudioRtpRecordHandler(); virtual ~AudioRtpRecordHandler();
/** /**
......
...@@ -87,51 +87,26 @@ Call::getState() ...@@ -87,51 +87,26 @@ Call::getState()
std::string std::string
Call::getStateStr () Call::getStateStr ()
{ {
CallState state = getState(); switch (getState()) {
ConnectionState connection = getConnectionState ();
CallType type = _type;
std::string state_str;
switch (state) {
case Active: case Active:
switch (connection) { switch (getConnectionState()) {
case Ringing: case Ringing: return isIncoming() ? "INCOMING" : "RINGING";
(type == Incoming) ? state_str = "INCOMING":state_str = "RINGING";
break;
case Connected: case Connected:
default: default: return isRecording() ? "RECORD" : "CURRENT";
isRecording() ? state_str = "RECORD" : state_str = "CURRENT";
break;
} }
case Hold: case Hold: return "HOLD";
state_str = "HOLD"; case Busy: return "BUSY";
break;
case Busy:
state_str = "BUSY";
break;
case Inactive: case Inactive:
switch (connection) { switch (getConnectionState()) {
case Ringing: case Ringing: return isIncoming() ? "INCOMING" : "RINGING";
(type == Incoming) ? state_str = "INCOMING":state_str = "RINGING"; case Connected: return "CURRENT";
break; default: return "INACTIVE";
case Connected:
state_str = "CURRENT";
break;
default:
state_str = "INACTIVE";
break;
} }
break; case Conferencing: return "CONFERENCING";
case Conferencing:
state_str = "CONFERENCING";
break;
case Refused: case Refused:
case Error: case Error:
default: default: return "FAILURE";
state_str = "FAILURE";
break;
} }
return state_str;
} }
...@@ -152,36 +127,20 @@ Call::getLocalAudioPort() ...@@ -152,36 +127,20 @@ Call::getLocalAudioPort()
bool bool
Call::setRecording() Call::setRecording()
{ {
_debug ("Call: Set recording");
bool recordStatus = Recordable::recAudio.isRecording(); bool recordStatus = Recordable::recAudio.isRecording();
Recordable::recAudio.setRecording(); Recordable::recAudio.setRecording();
// Start recording
if (!recordStatus) {
_debug ("Call: Call not recording yet, set ringbuffers");
MainBuffer *mbuffer = Manager::instance().getMainBuffer(); MainBuffer *mbuffer = Manager::instance().getMainBuffer();
std::string process_id = Recordable::recorder.getRecorderID(); std::string process_id = Recordable::recorder.getRecorderID();
if (!recordStatus) {
mbuffer->bindHalfDuplexOut (process_id, _id); mbuffer->bindHalfDuplexOut (process_id, _id);
mbuffer->bindHalfDuplexOut (process_id); mbuffer->bindHalfDuplexOut (process_id);
Recordable::recorder.start(); Recordable::recorder.start();
} } else {
// Stop recording
else {
_debug ("Call: Stop recording");
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
std::string process_id = Recordable::recorder.getRecorderID();
mbuffer->unBindHalfDuplexOut (process_id, _id); mbuffer->unBindHalfDuplexOut (process_id, _id);
mbuffer->unBindHalfDuplexOut (process_id); mbuffer->unBindHalfDuplexOut (process_id);
} }
Manager::instance().getMainBuffer()->stateInfo(); Manager::instance().getMainBuffer()->stateInfo();
......
...@@ -170,7 +170,7 @@ class Call: public Recordable ...@@ -170,7 +170,7 @@ class Call: public Recordable
* false otherwise * false otherwise
*/ */
bool isIncoming() { bool isIncoming() {
return (_type == Incoming) ? true : false; return _type == Incoming;
} }
/** /**
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "global.h" #include "global.h"
#include "callmanager.h" #include "callmanager.h"
#include "sip/sipcall.h"
#include "sip/sipvoiplink.h" #include "sip/sipvoiplink.h"
#include "audio/audiortp/AudioRtpFactory.h" #include "audio/audiortp/AudioRtpFactory.h"
#include "audio/audiortp/AudioZrtpSession.h" #include "audio/audiortp/AudioZrtpSession.h"
...@@ -366,26 +367,15 @@ sfl::AudioZrtpSession * CallManager::getAudioZrtpSession (const std::string& cal ...@@ -366,26 +367,15 @@ sfl::AudioZrtpSession * CallManager::getAudioZrtpSession (const std::string& cal
SIPCall *call; SIPCall *call;
try { try {
call = link->getSIPCall (callID); call = link->getSIPCall(callID);
} }
catch (const VoipLinkException &e) { catch (const VoipLinkException &e) {
throw CallManagerException("Call id " + callID + " is not valid"); throw CallManagerException("Call id " + callID + " is not valid");
} }
sfl::AudioRtpFactory * audioRtp = NULL; sfl::AudioZrtpSession * zSession = call->getAudioRtp()->getAudioZrtpSession();
audioRtp = call->getAudioRtp(); if (!zSession)
if (!audioRtp) {
throw CallManagerException("Failed to get AudioRtpFactory");
}
sfl::AudioZrtpSession * zSession = NULL;
zSession = audioRtp->getAudioZrtpSession();
if (!zSession) {
throw CallManagerException("Failed to get AudioZrtpSession"); throw CallManagerException("Failed to get AudioZrtpSession");
}
return zSession; return zSession;
} }
......
...@@ -6,7 +6,6 @@ libsiplink_la_SOURCES = \ ...@@ -6,7 +6,6 @@ libsiplink_la_SOURCES = \
Pattern.cpp \ Pattern.cpp \
SdesNegotiator.cpp \ SdesNegotiator.cpp \
sdp.cpp \ sdp.cpp \
sdpmedia.cpp \
sipaccount.cpp \ sipaccount.cpp \
sipcall.cpp \ sipcall.cpp \
sipvoiplink.cpp sipvoiplink.cpp
...@@ -15,7 +14,6 @@ noinst_HEADERS = \ ...@@ -15,7 +14,6 @@ noinst_HEADERS = \
Pattern.h \ Pattern.h \
SdesNegotiator.h \ SdesNegotiator.h \
sdp.h \ sdp.h \
sdpmedia.h \
sipaccount.h \ sipaccount.h \
sipcall.h \ sipcall.h \
sipvoiplink.h sipvoiplink.h
......
This diff is collapsed.
...@@ -45,10 +45,10 @@ ...@@ -45,10 +45,10 @@
#include <stdexcept> #include <stdexcept>
#include "global.h" // for CodecOrder #include "global.h" // for CodecOrder
class sdpMedia;
namespace sfl { namespace sfl {
class AudioCodec; class AudioCodec;
class Codec;
} }
class SdpException : public std::runtime_error class SdpException : public std::runtime_error
...@@ -140,13 +140,13 @@ class Sdp ...@@ -140,13 +140,13 @@ class Sdp
* Return the codec of the first media after negotiation * Return the codec of the first media after negotiation
* @throw SdpException * @throw SdpException
*/ */
sfl::AudioCodec* getSessionMedia (void); sfl::AudioCodec* getSessionMedia (void) const;
/* /*
* On building an invite outside a dialog, build the local offer and create the * On building an invite outside a dialog, build the local offer and create the
* SDP negotiator instance with it. * SDP negotiator instance with it.
*/ */
int createOffer (const CodecOrder &selectedCodecs); void createOffer (const CodecOrder &selectedCodecs);
/* /*
* On receiving an invite outside a dialog, build the local offer and create the * On receiving an invite outside a dialog, build the local offer and create the
...@@ -154,36 +154,13 @@ class Sdp ...@@ -154,36 +154,13 @@ class Sdp
* *
* @param remote The remote offer * @param remote The remote offer
*/ */
int receiveOffer (const pjmedia_sdp_session* remote, void receiveOffer (const pjmedia_sdp_session* remote,
const CodecOrder &selectedCodecs); const CodecOrder &selectedCodecs);
/*
* On receiving a message, check if it contains SDP and negotiate. Should be used for
* SDP answer and offer but currently is only used for answer.
* SDP negotiator instance with the remote offer.
*
* @param inv The the invitation
* @param rdata The remote data
*/
int receivingAnswerAfterInitialOffer(const pjmedia_sdp_session* remote);
/**
* Generate answer after receiving Initial Offer
*/
int generateAnswerAfterInitialOffer(void);
/** /**
* Start the sdp negotiation. * Start the sdp negotiation.
*
* @return pj_status_t 0 on success
* 1 otherwise
*/ */
pj_status_t startNegotiation (void); void startNegotiation (void);
/**
* Update internal state after negotiation
*/
void updateInternalState(void);
/** /**
* Remove all media in the session media vector. * Remove all media in the session media vector.
...@@ -195,15 +172,6 @@ class Sdp ...@@ -195,15 +172,6 @@ class Sdp
*/ */
void cleanLocalMediaCapabilities (void); void cleanLocalMediaCapabilities (void);
/*
* Attribute the specified port to every medias provided
* This is valid only because we are using one media
* We should change this to support multiple medias
*
* @param port The media port
*/
void setPortToAllMedia (int port);
/* /*
* Write accessor. Set the local IP address that will be used in the sdp session * Write accessor. Set the local IP address that will be used in the sdp session
*/ */
...@@ -264,23 +232,15 @@ class Sdp ...@@ -264,23 +232,15 @@ class Sdp
return remoteAudioPort_; return remoteAudioPort_;
} }
/**
* Get media list for this session
*/
std::vector<sdpMedia *> getSessionMediaList (void) const {
return sessionAudioMedia_;
}
/** /**
* *
*/ */
void addAttributeToLocalAudioMedia(std::string); void addAttributeToLocalAudioMedia(const char *);
/** /**
* *
*/ */
void removeAttributeFromLocalAudioMedia(std::string); void removeAttributeFromLocalAudioMedia(const char *);
/** /**
* Get SRTP master key * Get SRTP master key
...@@ -311,6 +271,12 @@ class Sdp ...@@ -311,6 +271,12 @@ class Sdp
return telephoneEventPayload_; return telephoneEventPayload_;
} }
void setMediaTransportInfoFromRemoteSdp();
std::string getCodecName(void) const;
void receivingAnswerAfterInitialOffer(const pjmedia_sdp_session* remote);
private: private:
/** /**
* The pool to allocate memory, ownership to SipCall * The pool to allocate memory, ownership to SipCall
...@@ -348,12 +314,12 @@ class Sdp ...@@ -348,12 +314,12 @@ class Sdp
/** /**
* Codec Map used for offer * Codec Map used for offer
*/ */
std::vector<sdpMedia *> localAudioMediaCap_; std::vector< sfl::Codec* > codec_list_;
/** /**
* The media that will be used by the session (after the SDP negotiation) * The media that will be used by the session (after the SDP negotiation)
*/ */
std::vector<sdpMedia *> sessionAudioMedia_; std::vector< sfl::Codec* > sessionAudioMedia_;
/** /**
* IP address * IP address
...@@ -397,11 +363,8 @@ class Sdp ...@@ -397,11 +363,8 @@ class Sdp
/* /*
* Build the sdp media section * Build the sdp media section
* Add rtpmap field if necessary * Add rtpmap field if necessary
*
* @param media The media to add to SDP
* @param med The structure to receive the media section
*/ */
void setMediaDescriptorLine (sdpMedia* media, pjmedia_sdp_media** p_med); pjmedia_sdp_media *setMediaDescriptorLine();
void setTelephoneEventRtpmap(pjmedia_sdp_media *med); void setTelephoneEventRtpmap(pjmedia_sdp_media *med);
...@@ -415,83 +378,6 @@ class Sdp ...@@ -415,83 +378,6 @@ class Sdp
* Build the local SDP offer * Build the local SDP offer
*/ */
int createLocalSession (const CodecOrder &selectedCodecs); int createLocalSession (const CodecOrder &selectedCodecs);
/*
* Mandatory field: Protocol version ("v=")
* Add the protocol version in the SDP session description
*/
void addProtocol (void);
/*
* Mandatory field: Origin ("o=")
* Gives the originator of the session.
* Serves as a globally unique identifier for this version of this session description.
*/
void addOrigin (void);
/*
* Mandatory field: Session name ("s=")
* Add a textual session name.
*/
void addSessionName (void);
/*
* Optional field: Connection data ("c=")
* Contains connection data.
*/
void addConnectionInfo (void);
/*
* Mandatory field: Timing ("t=")
* Specify the start and the stop time for a session.
*/
void addTiming (void);
/*
* Optional field: Session information ("s=")
* Provides textual information about the session.
*/
void addSessionInfo (void) {}
/*
* Optional field: Uri ("u=")
* Add a pointer to additional information about the session.
*/
void addUri (void) {}
/*
* Optional fields: Email address and phone number ("e=" and "p=")
* Add contact information for the person responsible for the conference.
*/
void addEmail (void) {}
/*
* Optional field: Bandwidth ("b=")
* Denotes the proposed bandwidth to be used by the session or the media .
*/
void addBandwidth (void) {}
/*
* Optional field: Time zones ("z=")
*/
void addTimeZone (void) {}
/*
* Optional field: Encryption keys ("k=")
*/
void addEncryptionKey (void) {}
/*
* Optional field: Attributes ("a=")
*/
void addAttributes();
/*
* Mandatory field: Media descriptions ("m=")
*/
void addAudioMediaDescription();
/* /*
* Adds a sdes attribute to the given media section. * Adds a sdes attribute to the given media section.
* *
...@@ -511,16 +397,6 @@ class Sdp ...@@ -511,16 +397,6 @@ class Sdp
* @throw SdpException * @throw SdpException
*/ */
void addZrtpAttribute (pjmedia_sdp_media* media, std::string hash); void addZrtpAttribute (pjmedia_sdp_media* media, std::string hash);
void setRemoteIpFromSdp (const pjmedia_sdp_session *r_sdp);
void setRemoteAudioPortFromSdp (pjmedia_sdp_media *r_media);
void setMediaTransportInfoFromRemoteSdp (const pjmedia_sdp_session *remote_sdp);
void getRemoteSdpTelephoneEventFromOffer(const pjmedia_sdp_session *remote_sdp);
void getRemoteSdpMediaFromOffer (const pjmedia_sdp_session* remote_sdp, pjmedia_sdp_media** r_media);
}; };
......
/*
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
*
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
*
* This file is free software: you can redistribute it and*or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sropulpof 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.
*
* You should have received a copy of the GNU General Public License
* along with Sropulpof. If not, see <http:*www.gnu.org*licenses*>.
*
* 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.
*/
#include "sdpmedia.h"
#include <string.h>
#include <sstream>