Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
25beb37d
Commit
25beb37d
authored
Sep 15, 2011
by
Rafaël Carré
Browse files
* #6905: simplify SIP code
try to make it more readable/understandable
parent
7c87bca1
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
daemon/src/account.h
View file @
25beb37d
...
...
@@ -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_MAILBOX
=
"Account.mailbox"
;
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_CREDENTIAL_NUMBER
=
"Credential.count"
;
static
const
char
*
const
ACCOUNT_DTMF_TYPE
=
"Account.dtmfType"
;
...
...
daemon/src/audio/audiortp/AudioRtpFactory.cpp
View file @
25beb37d
...
...
@@ -248,5 +248,3 @@ void AudioRtpFactory::sendDtmfDigit (int digit)
}
}
daemon/src/audio/audiortp/AudioRtpRecordHandler.cpp
View file @
25beb37d
...
...
@@ -30,6 +30,7 @@
#include
"AudioRtpRecordHandler.h"
#include
<fstream>
#include
"sip/sipcall.h"
#include
"audio/audiolayer.h"
#include
"manager.h"
...
...
daemon/src/audio/audiortp/AudioRtpRecordHandler.h
View file @
25beb37d
...
...
@@ -36,7 +36,7 @@ using std::ptrdiff_t;
#include
<ccrtp/rtp.h>
#include
<list>
#include
"sip/sipcall.h"
class
SIPCall
;
#include
"audio/codecs/audiocodec.h"
#include
"audio/samplerateconverter.h"
#include
"audio/noisesuppress.h"
...
...
@@ -105,7 +105,7 @@ class AudioRtpRecord
class
AudioRtpRecordHandler
{
public:
AudioRtpRecordHandler
(
SIPCall
*
ca
);
AudioRtpRecordHandler
(
SIPCall
*
);
virtual
~
AudioRtpRecordHandler
();
/**
...
...
daemon/src/call.cpp
View file @
25beb37d
...
...
@@ -87,51 +87,26 @@ Call::getState()
std
::
string
Call
::
getStateStr
()
{
CallState
state
=
getState
();
ConnectionState
connection
=
getConnectionState
();
CallType
type
=
_type
;
std
::
string
state_str
;
switch
(
state
)
{
switch
(
getState
())
{
case
Active
:
switch
(
connection
)
{
case
Ringing
:
(
type
==
Incoming
)
?
state_str
=
"INCOMING"
:
state_str
=
"RINGING"
;
break
;
switch
(
getConnectionState
())
{
case
Ringing
:
return
isIncoming
()
?
"INCOMING"
:
"RINGING"
;
case
Connected
:
default:
isRecording
()
?
state_str
=
"RECORD"
:
state_str
=
"CURRENT"
;
break
;
default:
return
isRecording
()
?
"RECORD"
:
"CURRENT"
;
}
case
Hold
:
state_str
=
"HOLD"
;
break
;
case
Busy
:
state_str
=
"BUSY"
;
break
;
case
Hold
:
return
"HOLD"
;
case
Busy
:
return
"BUSY"
;
case
Inactive
:
switch
(
connection
)
{
case
Ringing
:
(
type
==
Incoming
)
?
state_str
=
"INCOMING"
:
state_str
=
"RINGING"
;
break
;
case
Connected
:
state_str
=
"CURRENT"
;
break
;
default:
state_str
=
"INACTIVE"
;
break
;
switch
(
getConnectionState
())
{
case
Ringing
:
return
isIncoming
()
?
"INCOMING"
:
"RINGING"
;
case
Connected
:
return
"CURRENT"
;
default:
return
"INACTIVE"
;
}
break
;
case
Conferencing
:
state_str
=
"CONFERENCING"
;
break
;
case
Conferencing
:
return
"CONFERENCING"
;
case
Refused
:
case
Error
:
default:
state_str
=
"FAILURE"
;
break
;
default:
return
"FAILURE"
;
}
return
state_str
;
}
...
...
@@ -152,36 +127,20 @@ Call::getLocalAudioPort()
bool
Call
::
setRecording
()
{
_debug
(
"Call: Set recording"
);
bool
recordStatus
=
Recordable
::
recAudio
.
isRecording
();
Recordable
::
recAudio
.
setRecording
();
MainBuffer
*
mbuffer
=
Manager
::
instance
().
getMainBuffer
();
std
::
string
process_id
=
Recordable
::
recorder
.
getRecorderID
();
// Start recording
if
(
!
recordStatus
)
{
_debug
(
"Call: Call not recording yet, set ringbuffers"
);
MainBuffer
*
mbuffer
=
Manager
::
instance
().
getMainBuffer
();
std
::
string
process_id
=
Recordable
::
recorder
.
getRecorderID
();
mbuffer
->
bindHalfDuplexOut
(
process_id
,
_id
);
mbuffer
->
bindHalfDuplexOut
(
process_id
);
Recordable
::
recorder
.
start
();
}
// Stop recording
else
{
_debug
(
"Call: Stop recording"
);
MainBuffer
*
mbuffer
=
Manager
::
instance
().
getMainBuffer
();
std
::
string
process_id
=
Recordable
::
recorder
.
getRecorderID
();
}
else
{
mbuffer
->
unBindHalfDuplexOut
(
process_id
,
_id
);
mbuffer
->
unBindHalfDuplexOut
(
process_id
);
}
Manager
::
instance
().
getMainBuffer
()
->
stateInfo
();
...
...
daemon/src/call.h
View file @
25beb37d
...
...
@@ -170,7 +170,7 @@ class Call: public Recordable
* false otherwise
*/
bool
isIncoming
()
{
return
(
_type
==
Incoming
)
?
true
:
false
;
return
_type
==
Incoming
;
}
/**
...
...
daemon/src/dbus/callmanager.cpp
View file @
25beb37d
...
...
@@ -33,6 +33,7 @@
#include
"global.h"
#include
"callmanager.h"
#include
"sip/sipcall.h"
#include
"sip/sipvoiplink.h"
#include
"audio/audiortp/AudioRtpFactory.h"
#include
"audio/audiortp/AudioZrtpSession.h"
...
...
@@ -366,26 +367,15 @@ sfl::AudioZrtpSession * CallManager::getAudioZrtpSession (const std::string& cal
SIPCall
*
call
;
try
{
call
=
link
->
getSIPCall
(
callID
);
call
=
link
->
getSIPCall
(
callID
);
}
catch
(
const
VoipLinkException
&
e
)
{
throw
CallManagerException
(
"Call id "
+
callID
+
" is not valid"
);
}
sfl
::
AudioRtpFactory
*
audioRtp
=
NULL
;
audioRtp
=
call
->
getAudioRtp
();
if
(
!
audioRtp
)
{
throw
CallManagerException
(
"Failed to get AudioRtpFactory"
);
}
sfl
::
AudioZrtpSession
*
zSession
=
NULL
;
zSession
=
audioRtp
->
getAudioZrtpSession
();
if
(
!
zSession
)
{
sfl
::
AudioZrtpSession
*
zSession
=
call
->
getAudioRtp
()
->
getAudioZrtpSession
();
if
(
!
zSession
)
throw
CallManagerException
(
"Failed to get AudioZrtpSession"
);
}
return
zSession
;
}
...
...
daemon/src/sip/Makefile.am
View file @
25beb37d
...
...
@@ -6,7 +6,6 @@ libsiplink_la_SOURCES = \
Pattern.cpp
\
SdesNegotiator.cpp
\
sdp.cpp
\
sdpmedia.cpp
\
sipaccount.cpp
\
sipcall.cpp
\
sipvoiplink.cpp
...
...
@@ -15,7 +14,6 @@ noinst_HEADERS = \
Pattern.h
\
SdesNegotiator.h
\
sdp.h
\
sdpmedia.h
\
sipaccount.h
\
sipcall.h
\
sipvoiplink.h
...
...
daemon/src/sip/sdp.cpp
View file @
25beb37d
This diff is collapsed.
Click to expand it.
daemon/src/sip/sdp.h
View file @
25beb37d
...
...
@@ -45,10 +45,10 @@
#include
<stdexcept>
#include
"global.h"
// for CodecOrder
class
sdpMedia
;
namespace
sfl
{
class
AudioCodec
;
class
Codec
;
}
class
SdpException
:
public
std
::
runtime_error
...
...
@@ -140,13 +140,13 @@ class Sdp
* Return the codec of the first media after negotiation
* @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
* 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
...
...
@@ -154,36 +154,13 @@ class Sdp
*
* @param remote The remote offer
*/
int
receiveOffer
(
const
pjmedia_sdp_session
*
remote
,
void
receiveOffer
(
const
pjmedia_sdp_session
*
remote
,
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.
*
* @return pj_status_t 0 on success
* 1 otherwise
*/
pj_status_t
startNegotiation
(
void
);
/**
* Update internal state after negotiation
*/
void
updateInternalState
(
void
);
void
startNegotiation
(
void
);
/**
* Remove all media in the session media vector.
...
...
@@ -195,15 +172,6 @@ class Sdp
*/
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
*/
...
...
@@ -264,23 +232,15 @@ class Sdp
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
...
...
@@ -311,6 +271,12 @@ class Sdp
return
telephoneEventPayload_
;
}
void
setMediaTransportInfoFromRemoteSdp
();
std
::
string
getCodecName
(
void
)
const
;
void
receivingAnswerAfterInitialOffer
(
const
pjmedia_sdp_session
*
remote
);
private:
/**
* The pool to allocate memory, ownership to SipCall
...
...
@@ -348,12 +314,12 @@ class Sdp
/**
* 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)
*/
std
::
vector
<
sdpMedia
*
>
sessionAudioMedia_
;
std
::
vector
<
sfl
::
Codec
*
>
sessionAudioMedia_
;
/**
* IP address
...
...
@@ -397,11 +363,8 @@ class Sdp
/*
* Build the sdp media section
* 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
);
...
...
@@ -415,83 +378,6 @@ class Sdp
* Build the local SDP offer
*/
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.
*
...
...
@@ -511,16 +397,6 @@ class Sdp
* @throw SdpException
*/
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
);
};
...
...
daemon/src/sip/sdpmedia.cpp
deleted
100644 → 0
View file @
7c87bca1
/*
* 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>
#include
<iostream>
static
const
char
*
streamDirectionStr
[]
=
{
"sendrecv"
,
"sendonly"
,
"recvonly"
,
"inactive"
};
static
const
char
*
mediaTypeStr
[]
=
{
"audio"
,
"video"
,
"application"
,
"text"
,
"image"
,
"message"
};
sdpMedia
::
sdpMedia
(
int
type
)
:
_media_type
(
(
mediaType
)
type
),
_codec_list
(
0
),
_port
(
0
),
_stream_type
(
SEND_RECEIVE
)
{}
sdpMedia
::
sdpMedia
(
std
::
string
type
,
int
port
,
std
::
string
dir
)
:
_media_type
(
(
mediaType
)
-
1
),
_codec_list
(
0
),
_port
(
port
),
_stream_type
(
(
streamDirection
)
-
1
)
{
unsigned
int
i
;
const
char
*
tmp
;
for
(
i
=
0
;
i
<
MEDIA_COUNT
;
i
++
)
{
tmp
=
mediaTypeStr
[
i
];
if
(
strcmp
(
type
.
c_str
(),
tmp
)
==
0
)
{
_media_type
=
(
mediaType
)
i
;
break
;
}
}
if
(
strcmp
(
dir
.
c_str
(),
"default"
)
==
0
)
dir
=
DEFAULT_STREAM_DIRECTION
;
for
(
i
=
0
;
i
<
DIR_COUNT
;
i
++
)
{
tmp
=
streamDirectionStr
[
i
];
if
(
strcmp
(
dir
.
c_str
(),
tmp
)
==
0
)
{
_stream_type
=
(
streamDirection
)
i
;
break
;
}
}
}
sdpMedia
::~
sdpMedia
()
{
clear_codec_list
();
}
std
::
string
sdpMedia
::
get_media_type_str
(
void
)
{
std
::
string
value
;
// Test the range to be sure we know the media
if
(
_media_type
>=
0
&&
_media_type
<
MEDIA_COUNT
)
value
=
mediaTypeStr
[
_media_type
];
else
value
=
"unknown"
;
return
value
;
}
void
sdpMedia
::
add_codec
(
sfl
::
Codec
*
codec
)
{
_codec_list
.
push_back
(
codec
);
}
void
sdpMedia
::
remove_codec
(
std
::
string
codecName
)
{
// Look for the codec by its encoding name
std
::
vector
<
sfl
::
Codec
*>::
iterator
iter
;
size_t
size
=
_codec_list
.
size
();
for
(
unsigned
int
i
=
0
;
i
<
size
;
i
++
)
if
(
strcmp
(
_codec_list
[
i
]
->
getMimeSubtype
().
c_str
(),
codecName
.
c_str
())
==
0
)
{
iter
=
_codec_list
.
begin
()
+
i
;
_codec_list
.
erase
(
iter
);
break
;
}
}
void
sdpMedia
::
clear_codec_list
(
void
)
{
// Erase every codecs from the list
_codec_list
.
clear
();
}
std
::
string
sdpMedia
::
get_stream_direction_str
(
void
)
{
std
::
string
value
;
// Test the range of the value
if
(
_stream_type
>=
0
&&
_stream_type
<
DIR_COUNT
)
value
=
streamDirectionStr
[
_stream_type
];
else
value
=
"unknown"
;
return
value
;
}
std
::
string
sdpMedia
::
to_string
(
void
)
{
std
::
ostringstream
display
;
int
size
,
i
;
size
=
_codec_list
.
size
();
display
<<
get_media_type_str
();
display
<<
":"
<<
get_port
();
display
<<
":"
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
display
<<
_codec_list
[
i
]
->
getMimeSubtype
()
<<
"/"
;
}
display
<<
":"
<<
get_stream_direction_str
()
<<
std
::
endl
;
return
display
.
str
();
}