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
3bdfb413
Commit
3bdfb413
authored
Mar 30, 2012
by
Tristan Matthews
Browse files
* #9641: avoid dynamic memory allocs/raw pointer usage in audio rtp stack
parent
c6282441
Changes
13
Hide whitespace changes
Inline
Side-by-side
daemon/src/audio/audiortp/audio_rtp_factory.cpp
View file @
3bdfb413
...
...
@@ -91,7 +91,7 @@ void AudioRtpFactory::initSession()
switch
(
keyExchangeProtocol_
)
{
case
ZRTP
:
rtpSession_
=
new
AudioZrtpSession
(
ca_
,
zidFilename
);
rtpSession_
=
new
AudioZrtpSession
(
*
ca_
,
zidFilename
);
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's
// not even available at that point.
if
(
helloHashEnabled_
)
...
...
@@ -99,14 +99,14 @@ void AudioRtpFactory::initSession()
break
;
case
SDES
:
rtpSession_
=
new
AudioSrtpSession
(
ca_
);
rtpSession_
=
new
AudioSrtpSession
(
*
ca_
);
break
;
default:
throw
UnsupportedRtpSessionType
(
"Unsupported Rtp Session Exception Type!"
);
}
}
else
rtpSession_
=
new
AudioSymmetricRtpSession
(
ca_
);
rtpSession_
=
new
AudioSymmetricRtpSession
(
*
ca_
);
}
void
AudioRtpFactory
::
start
(
AudioCodec
*
audiocodec
)
...
...
@@ -117,7 +117,7 @@ void AudioRtpFactory::start(AudioCodec* audiocodec)
if
(
keyExchangeProtocol_
==
SDES
and
localContext_
and
remoteContext_
)
static_cast
<
AudioSrtpSession
*>
(
rtpSession_
)
->
restoreCryptoContext
(
localContext_
,
remoteContext_
);
if
(
rtpSession_
->
startRtpThread
(
audiocodec
)
!=
0
)
if
(
rtpSession_
->
startRtpThread
(
*
audiocodec
)
!=
0
)
throw
AudioRtpFactoryException
(
"AudioRtpFactory: Error: Failed to start AudioRtpSession thread"
);
}
...
...
@@ -150,7 +150,7 @@ void AudioRtpFactory::updateSessionMedia(AudioCodec *audiocodec)
if
(
rtpSession_
==
NULL
)
throw
AudioRtpFactoryException
(
"AudioRtpFactory: Error: rtpSession_ was null when trying to update IP address"
);
rtpSession_
->
updateSessionMedia
(
audiocodec
);
rtpSession_
->
updateSessionMedia
(
*
audiocodec
);
}
void
AudioRtpFactory
::
updateDestinationIpAddress
()
...
...
daemon/src/audio/audiortp/audio_rtp_record_handler.cpp
View file @
3bdfb413
...
...
@@ -67,13 +67,17 @@ AudioRtpRecord::~AudioRtpRecord()
}
AudioRtpRecordHandler
::
AudioRtpRecordHandler
(
SIPCall
*
ca
)
:
audioRtpRecord_
(),
id_
(
ca
->
getCallId
()),
echoCanceller
(
ca
->
getMemoryPool
()),
gainController
(
8000
,
-
10.0
)
AudioRtpRecordHandler
::
AudioRtpRecordHandler
(
SIPCall
&
call
)
:
audioRtpRecord_
(),
id_
(
call
.
getCallId
()),
echoCanceller
(
call
.
getMemoryPool
()),
gainController
(
8000
,
-
10.0
)
{}
AudioRtpRecordHandler
::~
AudioRtpRecordHandler
()
{}
void
AudioRtpRecordHandler
::
setRtpMedia
(
AudioCodec
*
audioCodec
)
void
AudioRtpRecordHandler
::
setRtpMedia
(
AudioCodec
*
audioCodec
)
{
ost
::
MutexLock
lock
(
audioRtpRecord_
.
audioCodecMutex_
);
...
...
daemon/src/audio/audiortp/audio_rtp_record_handler.h
View file @
3bdfb413
...
...
@@ -103,7 +103,7 @@ class AudioRtpRecord {
class
AudioRtpRecordHandler
{
public:
AudioRtpRecordHandler
(
SIPCall
*
);
AudioRtpRecordHandler
(
SIPCall
&
);
virtual
~
AudioRtpRecordHandler
();
/**
...
...
daemon/src/audio/audiortp/audio_rtp_session.cpp
View file @
3bdfb413
...
...
@@ -43,9 +43,9 @@
#include
"manager.h"
namespace
sfl
{
AudioRtpSession
::
AudioRtpSession
(
SIPCall
*
sip
call
,
ost
::
RTPDataQueue
*
queue
,
ost
::
Thread
*
thread
)
:
AudioRtpRecordHandler
(
sip
call
)
,
ca_
(
sip
call
)
AudioRtpSession
::
AudioRtpSession
(
SIPCall
&
call
,
ost
::
RTPDataQueue
&
queue
,
ost
::
Thread
&
thread
)
:
AudioRtpRecordHandler
(
call
)
,
ca
ll
_
(
call
)
,
timestamp_
(
0
)
,
timestampIncrement_
(
0
)
,
queue_
(
queue
)
...
...
@@ -55,16 +55,15 @@ AudioRtpSession::AudioRtpSession(SIPCall * sipcall, ost::RTPDataQueue *queue, os
,
timestampCount_
(
0
)
,
thread_
(
thread
)
{
assert
(
ca_
);
queue_
->
setTypeOfService
(
ost
::
RTPDataQueue
::
tosEnhanced
);
queue_
.
setTypeOfService
(
ost
::
RTPDataQueue
::
tosEnhanced
);
}
AudioRtpSession
::~
AudioRtpSession
()
{
queue_
->
disableStack
();
queue_
.
disableStack
();
}
void
AudioRtpSession
::
updateSessionMedia
(
AudioCodec
*
audioCodec
)
void
AudioRtpSession
::
updateSessionMedia
(
AudioCodec
&
audioCodec
)
{
int
lastSamplingRate
=
audioRtpRecord_
.
codecSampleRate_
;
...
...
@@ -79,9 +78,9 @@ void AudioRtpSession::updateSessionMedia(AudioCodec *audioCodec)
}
void
AudioRtpSession
::
setSessionMedia
(
AudioCodec
*
audioCodec
)
void
AudioRtpSession
::
setSessionMedia
(
AudioCodec
&
audioCodec
)
{
setRtpMedia
(
audioCodec
);
setRtpMedia
(
&
audioCodec
);
// store codec info locally
int
payloadType
=
getCodecPayloadType
();
...
...
@@ -102,14 +101,14 @@ void AudioRtpSession::setSessionMedia(AudioCodec *audioCodec)
if
(
payloadType
==
g722PayloadType
)
{
DEBUG
(
"AudioRtpSession: Setting G722 payload format"
);
queue_
->
setPayloadFormat
(
ost
::
DynamicPayloadFormat
((
ost
::
PayloadType
)
payloadType
,
g722RtpClockRate
));
queue_
.
setPayloadFormat
(
ost
::
DynamicPayloadFormat
((
ost
::
PayloadType
)
payloadType
,
g722RtpClockRate
));
}
else
{
if
(
dynamic
)
{
DEBUG
(
"AudioRtpSession: Setting dynamic payload format"
);
queue_
->
setPayloadFormat
(
ost
::
DynamicPayloadFormat
((
ost
::
PayloadType
)
payloadType
,
smplRate
));
queue_
.
setPayloadFormat
(
ost
::
DynamicPayloadFormat
((
ost
::
PayloadType
)
payloadType
,
smplRate
));
}
else
{
DEBUG
(
"AudioRtpSession: Setting static payload format"
);
queue_
->
setPayloadFormat
(
ost
::
StaticPayloadFormat
((
ost
::
StaticPayloadType
)
payloadType
));
queue_
.
setPayloadFormat
(
ost
::
StaticPayloadFormat
((
ost
::
StaticPayloadType
)
payloadType
));
}
}
}
...
...
@@ -138,20 +137,20 @@ void AudioRtpSession::sendDtmfEvent()
processDataEncode
();
// change Payload type for DTMF payload
queue_
->
setPayloadFormat
(
ost
::
DynamicPayloadFormat
((
ost
::
PayloadType
)
getDtmfPayloadType
(),
8000
));
queue_
.
setPayloadFormat
(
ost
::
DynamicPayloadFormat
((
ost
::
PayloadType
)
getDtmfPayloadType
(),
8000
));
queue_
->
setMark
(
true
);
queue_
->
sendImmediate
(
timestamp_
,
(
const
unsigned
char
*
)(
&
payload
),
sizeof
(
payload
));
queue_
->
setMark
(
false
);
queue_
.
setMark
(
true
);
queue_
.
sendImmediate
(
timestamp_
,
(
const
unsigned
char
*
)(
&
payload
),
sizeof
(
payload
));
queue_
.
setMark
(
false
);
// get back the payload to audio
queue_
->
setPayloadFormat
(
ost
::
StaticPayloadFormat
((
ost
::
StaticPayloadType
)
getCodecPayloadType
()));
queue_
.
setPayloadFormat
(
ost
::
StaticPayloadFormat
((
ost
::
StaticPayloadType
)
getCodecPayloadType
()));
}
void
AudioRtpSession
::
receiveSpeakerData
()
{
const
ost
::
AppDataUnit
*
adu
=
queue_
->
getData
(
queue_
->
getFirstTimestamp
());
const
ost
::
AppDataUnit
*
adu
=
queue_
.
getData
(
queue_
.
getFirstTimestamp
());
if
(
!
adu
)
return
;
...
...
@@ -179,7 +178,7 @@ void AudioRtpSession::sendMicData()
timestamp_
+=
timestampIncrement_
;
// putData puts the data on RTP queue, sendImmediate bypass this queue
queue_
->
sendImmediate
(
timestamp_
,
getMicDataEncoded
(),
compSize
);
queue_
.
sendImmediate
(
timestamp_
,
getMicDataEncoded
(),
compSize
);
}
...
...
@@ -187,28 +186,28 @@ void AudioRtpSession::setSessionTimeouts()
{
DEBUG
(
"AudioRtpSession: Set session scheduling timeout (%d) and expireTimeout (%d)"
,
sfl
::
schedulingTimeout
,
sfl
::
expireTimeout
);
queue_
->
setSchedulingTimeout
(
sfl
::
schedulingTimeout
);
queue_
->
setExpireTimeout
(
sfl
::
expireTimeout
);
queue_
.
setSchedulingTimeout
(
sfl
::
schedulingTimeout
);
queue_
.
setExpireTimeout
(
sfl
::
expireTimeout
);
}
void
AudioRtpSession
::
setDestinationIpAddress
()
{
// Store remote ip in case we would need to forget current destination
remote_ip_
=
ost
::
InetHostAddress
(
ca
_
->
getLocalSDP
()
->
getRemoteIP
().
c_str
());
remote_ip_
=
ost
::
InetHostAddress
(
ca
ll_
.
getLocalSDP
()
->
getRemoteIP
().
c_str
());
if
(
!
remote_ip_
)
{
WARN
(
"AudioRtpSession: Target IP address (%s) is not correct!"
,
ca
_
->
getLocalSDP
()
->
getRemoteIP
().
data
());
ca
ll_
.
getLocalSDP
()
->
getRemoteIP
().
data
());
return
;
}
// Store remote port in case we would need to forget current destination
remote_port_
=
(
unsigned
short
)
ca
_
->
getLocalSDP
()
->
getRemoteAudioPort
();
remote_port_
=
(
unsigned
short
)
ca
ll_
.
getLocalSDP
()
->
getRemoteAudioPort
();
DEBUG
(
"AudioRtpSession: New remote address for session: %s:%d"
,
ca
_
->
getLocalSDP
()
->
getRemoteIP
().
data
(),
remote_port_
);
ca
ll_
.
getLocalSDP
()
->
getRemoteIP
().
data
(),
remote_port_
);
if
(
!
queue_
->
addDestination
(
remote_ip_
,
remote_port_
))
{
if
(
!
queue_
.
addDestination
(
remote_ip_
,
remote_port_
))
{
WARN
(
"AudioRtpSession: Can't add new destination to session!"
);
return
;
}
...
...
@@ -221,7 +220,7 @@ void AudioRtpSession::updateDestinationIpAddress()
// Destination address are stored in a list in ccrtp
// This method remove the current destination entry
if
(
!
queue_
->
forgetDestination
(
remote_ip_
,
remote_port_
,
remote_port_
+
1
))
if
(
!
queue_
.
forgetDestination
(
remote_ip_
,
remote_port_
,
remote_port_
+
1
))
DEBUG
(
"AudioRtpSession: Did not remove previous destination"
);
// new destination is stored in call
...
...
@@ -230,7 +229,7 @@ void AudioRtpSession::updateDestinationIpAddress()
}
int
AudioRtpSession
::
startRtpThread
(
AudioCodec
*
audiocodec
)
int
AudioRtpSession
::
startRtpThread
(
AudioCodec
&
audiocodec
)
{
if
(
isStarted_
)
return
0
;
...
...
@@ -243,8 +242,8 @@ int AudioRtpSession::startRtpThread(AudioCodec* audiocodec)
initBuffers
();
initNoiseSuppress
();
queue_
->
enableStack
();
return
thread_
->
start
();
queue_
.
enableStack
();
return
thread_
.
start
();
}
...
...
daemon/src/audio/audiortp/audio_rtp_session.h
View file @
3bdfb413
...
...
@@ -31,16 +31,18 @@
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef
SFL_
AUDIO_RTP_SESSION_H_
#define
SFL_
AUDIO_RTP_SESSION_H_
#ifndef AUDIO_RTP_SESSION_H_
#define AUDIO_RTP_SESSION_H_
#include
"audio_rtp_record_handler.h"
#include
<audio/codecs/audiocodec.h>
#include
<ccrtp/rtp.h>
#include
<ccrtp/formats.h>
#include
"noncopyable.h"
class
SIPCall
;
namespace
ost
{
class
Thread
;
}
namespace
sfl
{
...
...
@@ -52,12 +54,12 @@ class AudioRtpSession : public AudioRtpRecordHandler {
* Constructor
* @param sipcall The pointer on the SIP call
*/
AudioRtpSession
(
SIPCall
*
sipcall
,
ost
::
RTPDataQueue
*
queue
,
ost
::
Thread
*
thread
);
AudioRtpSession
(
SIPCall
&
sipcall
,
ost
::
RTPDataQueue
&
queue
,
ost
::
Thread
&
thread
);
virtual
~
AudioRtpSession
();
void
updateSessionMedia
(
AudioCodec
*
audioCodec
);
void
updateSessionMedia
(
AudioCodec
&
audioCodec
);
virtual
int
startRtpThread
(
AudioCodec
*
);
virtual
int
startRtpThread
(
AudioCodec
&
);
/**
* Used mostly when receiving a reinvite
...
...
@@ -68,7 +70,7 @@ class AudioRtpSession : public AudioRtpRecordHandler {
/**
* Set the audio codec for this RTP session
*/
virtual
void
setSessionMedia
(
AudioCodec
*
codec
)
=
0
;
virtual
void
setSessionMedia
(
AudioCodec
&
codec
)
=
0
;
bool
onRTPPacketRecv
(
ost
::
IncomingRTPPkt
&
);
...
...
@@ -86,7 +88,7 @@ class AudioRtpSession : public AudioRtpRecordHandler {
*/
virtual
void
sendMicData
();
SIPCall
*
ca_
;
SIPCall
&
ca
ll
_
;
/**
* Timestamp for this session
...
...
@@ -99,7 +101,7 @@ class AudioRtpSession : public AudioRtpRecordHandler {
*/
int
timestampIncrement_
;
ost
::
RTPDataQueue
*
queue_
;
ost
::
RTPDataQueue
&
queue_
;
bool
isStarted_
;
private:
...
...
@@ -140,7 +142,7 @@ class AudioRtpSession : public AudioRtpRecordHandler {
*/
short
timestampCount_
;
ost
::
Thread
*
thread_
;
ost
::
Thread
&
thread_
;
};
}
...
...
daemon/src/audio/audiortp/audio_srtp_session.cpp
View file @
3bdfb413
...
...
@@ -29,8 +29,6 @@
*/
#include
"audio_srtp_session.h"
#include
"sip/sipcall.h"
#include
<openssl/sha.h>
#include
<openssl/hmac.h>
#include
<openssl/evp.h>
...
...
@@ -44,8 +42,8 @@
namespace
sfl
{
AudioSrtpSession
::
AudioSrtpSession
(
SIPCall
*
sip
call
)
:
AudioSymmetricRtpSession
(
sip
call
),
AudioSrtpSession
::
AudioSrtpSession
(
SIPCall
&
call
)
:
AudioSymmetricRtpSession
(
call
),
remoteCryptoCtx_
(
NULL
),
localCryptoCtx_
(
NULL
),
localCryptoSuite_
(
0
),
...
...
daemon/src/audio/audiortp/audio_srtp_session.h
View file @
3bdfb413
...
...
@@ -27,10 +27,9 @@
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef
__
AUDIO_SRTP_SESSION_H_
_
#define
__
AUDIO_SRTP_SESSION_H_
_
#ifndef AUDIO_SRTP_SESSION_H_
#define AUDIO_SRTP_SESSION_H_
#include
"audio_rtp_session.h"
#include
"audio_symmetric_rtp_session.h"
#include
"sip/sdes_negotiator.h"
#include
"noncopyable.h"
...
...
@@ -73,7 +72,7 @@ class AudioSrtpSession : public AudioSymmetricRtpSession {
/**
* Constructor for this rtp session
*/
AudioSrtpSession
(
SIPCall
*
sip
call
);
AudioSrtpSession
(
SIPCall
&
call
);
/**
* Used to get sdp crypto header to be included in sdp session. This
...
...
@@ -85,7 +84,7 @@ class AudioSrtpSession : public AudioSymmetricRtpSession {
/**
* Set remote crypto header from incoming sdp offer
*/
void
setRemoteCryptoInfo
(
sfl
::
SdesNegotiator
&
nego
);
void
setRemoteCryptoInfo
(
sfl
::
SdesNegotiator
&
nego
);
/**
* Init local crypto context for outgoing data
...
...
daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp
View file @
3bdfb413
...
...
@@ -41,26 +41,26 @@
namespace
sfl
{
AudioSymmetricRtpSession
::
AudioSymmetricRtpSession
(
SIPCall
*
sip
call
)
:
AudioSymmetricRtpSession
::
AudioSymmetricRtpSession
(
SIPCall
&
call
)
:
ost
::
TimerPort
()
,
ost
::
SymmetricRTPSession
(
ost
::
InetHostAddress
(
sip
call
->
getLocalIp
().
c_str
()),
sip
call
->
getLocalAudioPort
())
,
AudioRtpSession
(
sip
call
,
this
,
this
)
,
rtpThread_
(
new
AudioRtpThread
(
this
)
)
,
ost
::
SymmetricRTPSession
(
ost
::
InetHostAddress
(
call
.
getLocalIp
().
c_str
()),
call
.
getLocalAudioPort
())
,
AudioRtpSession
(
call
,
*
this
,
*
this
)
,
rtpThread_
(
*
this
)
{
DEBUG
(
"AudioSymmetricRtpSession: Setting new RTP session with destination %s:%d"
,
ca
_
->
getLocalIp
().
c_str
(),
ca
_
->
getLocalAudioPort
());
audioRtpRecord_
.
callId_
=
ca
_
->
getCallId
();
DEBUG
(
"AudioSymmetricRtpSession: Setting new RTP session with destination %s:%d"
,
ca
ll_
.
getLocalIp
().
c_str
(),
ca
ll_
.
getLocalAudioPort
());
audioRtpRecord_
.
callId_
=
ca
ll_
.
getCallId
();
}
AudioSymmetricRtpSession
::~
AudioSymmetricRtpSession
()
{
rtpThread_
->
running_
=
false
;
delete
rtpThread_
;
if
(
rtpThread_
.
running_
)
{
rtpThread_
.
running_
=
false
;
rtpThread_
.
join
();
}
}
AudioSymmetricRtpSession
::
AudioRtpThread
::
AudioRtpThread
(
AudioSymmetricRtpSession
*
session
)
:
running_
(
true
),
rtpSession_
(
session
)
{
assert
(
rtpSession_
);
}
AudioSymmetricRtpSession
::
AudioRtpThread
::
AudioRtpThread
(
AudioSymmetricRtpSession
&
session
)
:
running_
(
true
),
rtpSession_
(
session
)
{}
void
AudioSymmetricRtpSession
::
AudioRtpThread
::
run
()
{
...
...
@@ -72,10 +72,10 @@ void AudioSymmetricRtpSession::AudioRtpThread::run()
while
(
running_
)
{
// Send session
if
(
rtpSession_
->
DtmfPending
())
rtpSession_
->
sendDtmfEvent
();
if
(
rtpSession_
.
DtmfPending
())
rtpSession_
.
sendDtmfEvent
();
else
rtpSession_
->
sendMicData
();
rtpSession_
.
sendMicData
();
Thread
::
sleep
(
TimerPort
::
getTimer
());
...
...
@@ -85,13 +85,13 @@ void AudioSymmetricRtpSession::AudioRtpThread::run()
DEBUG
(
"AudioRtpThread: Leaving audio rtp thread loop"
);
}
void
AudioSymmetricRtpSession
::
setSessionMedia
(
AudioCodec
*
audioCodec
)
void
AudioSymmetricRtpSession
::
setSessionMedia
(
AudioCodec
&
audioCodec
)
{
AudioRtpSession
::
setSessionMedia
(
audioCodec
);
ca
_
->
setRecordingSmplRate
(
getCodecSampleRate
());
ca
ll_
.
setRecordingSmplRate
(
getCodecSampleRate
());
}
int
AudioSymmetricRtpSession
::
startRtpThread
(
AudioCodec
*
audiocodec
)
int
AudioSymmetricRtpSession
::
startRtpThread
(
AudioCodec
&
audiocodec
)
{
DEBUG
(
"AudioSymmetricRtpSession: Starting main thread"
);
if
(
isStarted_
)
...
...
daemon/src/audio/audiortp/audio_symmetric_rtp_session.h
View file @
3bdfb413
...
...
@@ -56,9 +56,9 @@ class AudioSymmetricRtpSession : public ost::TimerPort, public ost::SymmetricRTP
public:
/**
* Constructor
* @param
sip
call The
pointer on the
SIP call
* @param call The SIP call
*/
AudioSymmetricRtpSession
(
SIPCall
*
sip
call
);
AudioSymmetricRtpSession
(
SIPCall
&
call
);
~
AudioSymmetricRtpSession
();
virtual
bool
onRTPPacketRecv
(
ost
::
IncomingRTPPkt
&
pkt
)
{
...
...
@@ -66,7 +66,7 @@ class AudioSymmetricRtpSession : public ost::TimerPort, public ost::SymmetricRTP
}
int
startSymmetricRtpThread
()
{
return
rtpThread_
->
start
();
return
rtpThread_
.
start
();
}
private:
...
...
@@ -74,7 +74,7 @@ class AudioSymmetricRtpSession : public ost::TimerPort, public ost::SymmetricRTP
class
AudioRtpThread
:
public
ost
::
Thread
,
public
ost
::
TimerPort
{
public:
AudioRtpThread
(
AudioSymmetricRtpSession
*
session
);
AudioRtpThread
(
AudioSymmetricRtpSession
&
session
);
virtual
void
run
();
...
...
@@ -82,12 +82,12 @@ class AudioSymmetricRtpSession : public ost::TimerPort, public ost::SymmetricRTP
private:
NON_COPYABLE
(
AudioRtpThread
);
AudioSymmetricRtpSession
*
rtpSession_
;
AudioSymmetricRtpSession
&
rtpSession_
;
};
void
setSessionMedia
(
AudioCodec
*
codec
);
int
startRtpThread
(
AudioCodec
*
audiocodec
);
void
setSessionMedia
(
AudioCodec
&
codec
);
int
startRtpThread
(
AudioCodec
&
audiocodec
);
AudioRtpThread
*
rtpThread_
;
AudioRtpThread
rtpThread_
;
};
}
...
...
daemon/src/audio/audiortp/audio_zrtp_session.cpp
View file @
3bdfb413
...
...
@@ -49,13 +49,13 @@
namespace
sfl
{
AudioZrtpSession
::
AudioZrtpSession
(
SIPCall
*
sip
call
,
const
std
::
string
&
zidFilename
)
:
AudioRtpSession
(
sip
call
,
this
,
this
),
ost
::
TRTPSessionBase
<
ost
::
SymmetricRTPChannel
,
ost
::
SymmetricRTPChannel
,
ost
::
ZrtpQueue
>
(
ost
::
InetHostAddress
(
sip
call
->
getLocalIp
().
c_str
()),
sip
call
->
getLocalAudioPort
(),
0
,
ost
::
MembershipBookkeeping
::
defaultMembersHashSize
,
ost
::
defaultApplication
()),
AudioZrtpSession
::
AudioZrtpSession
(
SIPCall
&
call
,
const
std
::
string
&
zidFilename
)
:
AudioRtpSession
(
call
,
*
this
,
*
this
),
ost
::
TRTPSessionBase
<
ost
::
SymmetricRTPChannel
,
ost
::
SymmetricRTPChannel
,
ost
::
ZrtpQueue
>
(
ost
::
InetHostAddress
(
call
_
.
getLocalIp
().
c_str
()),
call
_
.
getLocalAudioPort
(),
0
,
ost
::
MembershipBookkeeping
::
defaultMembersHashSize
,
ost
::
defaultApplication
()),
zidFilename_
(
zidFilename
)
{
DEBUG
(
"AudioZrtpSession initialized"
);
...
...
@@ -63,13 +63,14 @@ AudioZrtpSession::AudioZrtpSession(SIPCall * sipcall, const std::string& zidFile
setCancel
(
cancelDefault
);
DEBUG
(
"AudioZrtpSession: Setting new RTP session with destination %s:%d"
,
ca_
->
getLocalIp
().
c_str
(),
ca_
->
getLocalAudioPort
());
DEBUG
(
"AudioZrtpSession: Setting new RTP session with destination %s:%d"
,
call_
.
getLocalIp
().
c_str
(),
call_
.
getLocalAudioPort
());
}
AudioZrtpSession
::~
AudioZrtpSession
()
{
ost
::
Thread
::
terminate
();
Manager
::
instance
().
getMainBuffer
()
->
unBindAll
(
ca
_
->
getCallId
());
Manager
::
instance
().
getMainBuffer
()
->
unBindAll
(
ca
ll_
.
getCallId
());
}
void
AudioZrtpSession
::
final
()
...
...
@@ -102,7 +103,7 @@ void AudioZrtpSession::initializeZid()
if
(
initialize
(
zidCompleteFilename
.
c_str
())
>=
0
)
{
DEBUG
(
"Register callbacks"
);
setEnableZrtp
(
true
);
setUserCallback
(
new
ZrtpSessionCallback
(
ca_
));
setUserCallback
(
new
ZrtpSessionCallback
(
ca
ll
_
));
return
;
}
...
...
@@ -129,17 +130,17 @@ void AudioZrtpSession::sendMicData()
timestamp_
+=
timestampIncrement_
;
// this step is only needed for ZRTP
queue_
->
putData
(
timestamp_
,
getMicDataEncoded
(),
compSize
);
queue_
.
putData
(
timestamp_
,
getMicDataEncoded
(),
compSize
);
// putData puts the data on RTP queue, sendImmediate bypasses this queue
queue_
->
sendImmediate
(
timestamp_
,
getMicDataEncoded
(),
compSize
);
queue_
.
sendImmediate
(
timestamp_
,
getMicDataEncoded
(),
compSize
);
}
void
AudioZrtpSession
::
run
()
{
// Set recording sampling rate
ca
_
->
setRecordingSmplRate
(
getCodecSampleRate
());
DEBUG
(
"AudioZrtpSession: Entering mainloop for call %s"
,
ca
_
->
getCallId
().
c_str
());
ca
ll_
.
setRecordingSmplRate
(
getCodecSampleRate
());
DEBUG
(
"AudioZrtpSession: Entering mainloop for call %s"
,
ca
ll_
.
getCallId
().
c_str
());
uint32
timeout
=
0
;
...
...
@@ -169,7 +170,7 @@ void AudioZrtpSession::run()
setCancel
(
cancelImmediate
);
timerTick
();
}
else
{
if
(
isPendingData
(
timeout
/
1000
))
{
if
(
isPendingData
(
timeout
/
1000
))
{
setCancel
(
cancelDeferred
);
if
(
isActive
())
...
...
@@ -181,17 +182,15 @@ void AudioZrtpSession::run()
}
}
DEBUG
(
"AudioZrtpSession: Left main loop for call %s"
,
ca
_
->
getCallId
().
c_str
());
DEBUG
(
"AudioZrtpSession: Left main loop for call %s"
,
ca
ll_
.
getCallId
().
c_str
());
}
void
AudioZrtpSession
::
incrementTimestampForDTMF
()
{
timestamp_
+=
160
;
}
void
AudioZrtpSession
::
setSessionMedia
(
AudioCodec
*
audioCodec
)
void
AudioZrtpSession
::
setSessionMedia
(
AudioCodec
&
audioCodec
)
{
AudioRtpSession
::
setSessionMedia
(
audioCodec
);
}
...
...
daemon/src/audio/audiortp/audio_zrtp_session.h
View file @
3bdfb413
...
...
@@ -47,16 +47,17 @@ class AudioCodec;
namespace
sfl
{
class
ZrtpZidException
:
public
std
::
runtime_error
{
class
ZrtpZidException
:
public
std
::
runtime_error
{
public:
ZrtpZidException
(
const
std
::
string
&
str
=
""
)
:
std
::
runtime_error
(
"ZRTP ZID initialization failed."
+
str
)
{}
};
// class AudioZrtpSession : public ost::TimerPort, public ost::SymmetricZRTPSession, public AudioRtpRecordHandler
class
AudioZrtpSession
:
public
AudioRtpSession
,
protected
ost
::
Thread
,
public
ost
::
TRTPSessionBase
<
ost
::
SymmetricRTPChannel
,
ost
::
SymmetricRTPChannel
,
ost
::
ZrtpQueue
>
{
class
AudioZrtpSession
:
public
AudioRtpSession
,
protected
ost
::
Thread
,
public
ost
::
TRTPSessionBase
<
ost
::
SymmetricRTPChannel
,
ost
::
SymmetricRTPChannel
,
ost
::
ZrtpQueue
>
{
public:
AudioZrtpSession
(
SIPCall
*
sip
call
,
const
std
::
string
&
zidFilename
);
AudioZrtpSession
(
SIPCall
&
call
,
const
std
::
string
&
zidFilename
);
~
AudioZrtpSession
();
virtual
void
final
();
...
...
@@ -64,7 +65,7 @@ class AudioZrtpSession : public AudioRtpSession, protected ost::Thread, public o
// Thread associated method
virtual
void
run
();
virtual
bool
onRTPPacketRecv
(
ost
::
IncomingRTPPkt
&
pkt
)
{
virtual
bool
onRTPPacketRecv
(
ost
::
IncomingRTPPkt
&
pkt
)
{
return
AudioRtpSession
::
onRTPPacketRecv
(
pkt
);
}
...
...
@@ -73,7 +74,7 @@ class AudioZrtpSession : public AudioRtpSession, protected ost::Thread, public o
void
initializeZid
();