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
0f318251
Commit
0f318251
authored
Dec 24, 2012
by
Tristan Matthews
Browse files
* #18668: audiortp: remove duplicated code
parent
b9a1978c
Changes
6
Hide whitespace changes
Inline
Side-by-side
daemon/src/audio/audiortp/audio_rtp_session.cpp
View file @
0f318251
...
...
@@ -51,6 +51,7 @@ AudioRtpSession::AudioRtpSession(SIPCall &call, ost::RTPDataQueue &queue) :
,
remote_ip_
()
,
remote_port_
(
0
)
,
timestampCount_
(
0
)
,
rtpSendThread_
(
*
this
)
{
queue_
.
setTypeOfService
(
ost
::
RTPDataQueue
::
tosEnhanced
);
}
...
...
@@ -268,4 +269,52 @@ void AudioRtpSession::startRtpThreads(const std::vector<AudioCodec*> &audioCodec
startSendThread
();
}
AudioRtpSession
::
AudioRtpSendThread
::
AudioRtpSendThread
(
AudioRtpSession
&
session
)
:
running_
(
false
),
rtpSession_
(
session
),
thread_
(
0
),
timer_
()
{}
AudioRtpSession
::
AudioRtpSendThread
::~
AudioRtpSendThread
()
{
running_
=
false
;
if
(
thread_
)
pthread_join
(
thread_
,
NULL
);
}
void
AudioRtpSession
::
AudioRtpSendThread
::
start
()
{
running_
=
true
;
pthread_create
(
&
thread_
,
NULL
,
&
runCallback
,
this
);
}
void
*
AudioRtpSession
::
AudioRtpSendThread
::
runCallback
(
void
*
data
)
{
AudioRtpSession
::
AudioRtpSendThread
*
context
=
static_cast
<
AudioRtpSession
::
AudioRtpSendThread
*>
(
data
);
context
->
run
();
return
NULL
;
}
void
AudioRtpSession
::
AudioRtpSendThread
::
run
()
{
timer_
.
setTimer
(
rtpSession_
.
transportRate_
);
const
int
MS_TO_USEC
=
1000
;
while
(
running_
)
{
// Send session
if
(
rtpSession_
.
hasDTMFPending
())
rtpSession_
.
sendDtmfEvent
();
else
rtpSession_
.
sendMicData
();
usleep
(
timer_
.
getTimer
()
*
MS_TO_USEC
);
timer_
.
incTimer
(
rtpSession_
.
transportRate_
);
}
}
void
AudioRtpSession
::
startSendThread
()
{
rtpSendThread_
.
start
();
}
}
daemon/src/audio/audiortp/audio_rtp_session.h
View file @
0f318251
...
...
@@ -86,19 +86,6 @@ class AudioRtpSession : public AudioRtpRecordHandler {
bool
onRTPPacketRecv
(
ost
::
IncomingRTPPkt
&
);
/**
* Send DTMF over RTP (RFC2833). The timestamp and sequence number must be
* incremented as if it was microphone audio. This function change the payload type of the rtp session,
* send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get
* back the codec payload for further audio processing.
*/
void
sendDtmfEvent
();
/**
* Send encoded data to peer
*/
virtual
void
sendMicData
();
SIPCall
&
call_
;
/**
...
...
@@ -121,7 +108,37 @@ class AudioRtpSession : public AudioRtpRecordHandler {
private:
NON_COPYABLE
(
AudioRtpSession
);
virtual
void
startReceiveThread
()
=
0
;
virtual
void
startSendThread
()
=
0
;
void
startSendThread
();
/**
* Send DTMF over RTP (RFC2833). The timestamp and sequence number must be
* incremented as if it was microphone audio. This function change the payload type of the rtp session,
* send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get
* back the codec payload for further audio processing.
*/
void
sendDtmfEvent
();
/**
* Send encoded data to peer
*/
virtual
void
sendMicData
();
class
AudioRtpSendThread
{
public:
AudioRtpSendThread
(
AudioRtpSession
&
session
);
~
AudioRtpSendThread
();
void
start
();
bool
running_
;
private:
static
void
*
runCallback
(
void
*
data
);
void
run
();
NON_COPYABLE
(
AudioRtpSendThread
);
AudioRtpSession
&
rtpSession_
;
pthread_t
thread_
;
ost
::
TimerPort
timer_
;
};
/**
* Set RTP Sockets send/receive timeouts
...
...
@@ -152,6 +169,8 @@ class AudioRtpSession : public AudioRtpRecordHandler {
* Timestamp reset frequency specified in number of packet sent
*/
short
timestampCount_
;
AudioRtpSendThread
rtpSendThread_
;
};
}
...
...
daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp
View file @
0f318251
...
...
@@ -41,63 +41,14 @@ namespace sfl {
AudioSymmetricRtpSession
::
AudioSymmetricRtpSession
(
SIPCall
&
call
)
:
ost
::
SymmetricRTPSession
(
ost
::
InetHostAddress
(
call
.
getLocalIp
().
c_str
()),
call
.
getLocalAudioPort
())
,
AudioRtpSession
(
call
,
*
this
)
,
rtpSendThread_
(
*
this
)
{
DEBUG
(
"Setting new RTP session with destination %s:%d"
,
call_
.
getLocalIp
().
c_str
(),
call_
.
getLocalAudioPort
());
audioRtpRecord_
.
callId_
=
call_
.
getCallId
();
}
AudioSymmetricRtpSession
::
AudioRtpSendThread
::
AudioRtpSendThread
(
AudioSymmetricRtpSession
&
session
)
:
running_
(
false
),
rtpSession_
(
session
),
thread_
(
0
)
{}
AudioSymmetricRtpSession
::
AudioRtpSendThread
::~
AudioRtpSendThread
()
{
running_
=
false
;
if
(
thread_
)
pthread_join
(
thread_
,
NULL
);
}
void
AudioSymmetricRtpSession
::
AudioRtpSendThread
::
start
()
{
running_
=
true
;
pthread_create
(
&
thread_
,
NULL
,
&
runCallback
,
this
);
}
void
*
AudioSymmetricRtpSession
::
AudioRtpSendThread
::
runCallback
(
void
*
data
)
{
AudioSymmetricRtpSession
::
AudioRtpSendThread
*
context
=
static_cast
<
AudioSymmetricRtpSession
::
AudioRtpSendThread
*>
(
data
);
context
->
run
();
return
NULL
;
}
void
AudioSymmetricRtpSession
::
AudioRtpSendThread
::
run
()
{
ost
::
TimerPort
::
setTimer
(
rtpSession_
.
transportRate_
);
const
int
MS_TO_USEC
=
1000
;
while
(
running_
)
{
// Send session
if
(
rtpSession_
.
hasDTMFPending
())
rtpSession_
.
sendDtmfEvent
();
else
rtpSession_
.
sendMicData
();
usleep
(
ost
::
TimerPort
::
getTimer
()
*
MS_TO_USEC
);
ost
::
TimerPort
::
incTimer
(
rtpSession_
.
transportRate_
);
}
}
void
AudioSymmetricRtpSession
::
startReceiveThread
()
{
ost
::
SymmetricRTPSession
::
start
();
}
void
AudioSymmetricRtpSession
::
startSendThread
()
{
rtpSendThread_
.
start
();
}
}
daemon/src/audio/audiortp/audio_symmetric_rtp_session.h
View file @
0f318251
...
...
@@ -78,25 +78,7 @@ class AudioSymmetricRtpSession : public ost::TimerPort, public ost::SymmetricRTP
private:
NON_COPYABLE
(
AudioSymmetricRtpSession
);
class
AudioRtpSendThread
:
public
ost
::
TimerPort
{
public:
AudioRtpSendThread
(
AudioSymmetricRtpSession
&
session
);
~
AudioRtpSendThread
();
void
start
();
bool
running_
;
private:
NON_COPYABLE
(
AudioRtpSendThread
);
static
void
*
runCallback
(
void
*
data
);
void
run
();
pthread_t
thread_
;
AudioSymmetricRtpSession
&
rtpSession_
;
};
void
startReceiveThread
();
void
startSendThread
();
AudioRtpSendThread
rtpSendThread_
;
};
}
...
...
daemon/src/audio/audiortp/audio_zrtp_session.cpp
View file @
0f318251
...
...
@@ -50,7 +50,6 @@ AudioZrtpSession::AudioZrtpSession(SIPCall &call, const std::string &zidFilename
ost
::
SymmetricZRTPSession
(
ost
::
InetHostAddress
(
call
.
getLocalIp
().
c_str
()),
call
.
getLocalAudioPort
())
,
AudioRtpSession
(
call
,
*
this
)
,
zidFilename_
(
zidFilename
)
,
rtpSendThread_
(
*
this
)
{
initializeZid
();
DEBUG
(
"Setting new RTP session with destination %s:%d"
,
...
...
@@ -112,52 +111,6 @@ void AudioZrtpSession::sendMicData()
queue_
.
sendImmediate
(
timestamp_
,
getMicDataEncoded
(),
compSize
);
}
AudioZrtpSession
::
AudioZrtpSendThread
::
AudioZrtpSendThread
(
AudioZrtpSession
&
session
)
:
running_
(
true
),
zrtpSession_
(
session
),
thread_
(
0
)
{}
AudioZrtpSession
::
AudioZrtpSendThread
::~
AudioZrtpSendThread
()
{
running_
=
false
;
if
(
thread_
)
pthread_join
(
thread_
,
NULL
);
}
void
AudioZrtpSession
::
AudioZrtpSendThread
::
start
()
{
pthread_create
(
&
thread_
,
NULL
,
&
runCallback
,
this
);
}
void
*
AudioZrtpSession
::
AudioZrtpSendThread
::
runCallback
(
void
*
data
)
{
AudioZrtpSession
::
AudioZrtpSendThread
*
context
=
static_cast
<
AudioZrtpSession
::
AudioZrtpSendThread
*>
(
data
);
context
->
run
();
return
NULL
;
}
void
AudioZrtpSession
::
AudioZrtpSendThread
::
run
()
{
DEBUG
(
"Entering Audio zrtp thread main loop %s"
,
running_
?
"running"
:
"not running"
);
TimerPort
::
setTimer
(
zrtpSession_
.
transportRate_
);
while
(
running_
)
{
// Send session
if
(
zrtpSession_
.
hasDTMFPending
())
zrtpSession_
.
sendDtmfEvent
();
else
zrtpSession_
.
sendMicData
();
Thread
::
sleep
(
TimerPort
::
getTimer
());
TimerPort
::
incTimer
(
zrtpSession_
.
transportRate_
);
}
DEBUG
(
"Leaving audio rtp thread loop"
);
}
int
AudioZrtpSession
::
getIncrementForDTMF
()
const
{
return
160
;
...
...
@@ -168,9 +121,4 @@ void AudioZrtpSession::startReceiveThread()
ost
::
SymmetricZRTPSession
::
start
();
}
void
AudioZrtpSession
::
startSendThread
()
{
rtpSendThread_
.
start
();
}
}
daemon/src/audio/audiortp/audio_zrtp_session.h
View file @
0f318251
...
...
@@ -42,7 +42,6 @@ using std::ptrdiff_t;
#include
"global.h"
#include
"audio_rtp_session.h"
// #include <commoncpp/numbers.h> // OST::Time
class
SIPCall
;
class
AudioCodec
;
...
...
@@ -76,28 +75,11 @@ class AudioZrtpSession :
private:
NON_COPYABLE
(
AudioZrtpSession
);
class
AudioZrtpSendThread
:
public
ost
::
TimerPort
{
public:
AudioZrtpSendThread
(
AudioZrtpSession
&
session
);
~
AudioZrtpSendThread
();
void
start
();
bool
running_
;
private:
static
void
*
runCallback
(
void
*
data
);
void
run
();
NON_COPYABLE
(
AudioZrtpSendThread
);
AudioZrtpSession
&
zrtpSession_
;
pthread_t
thread_
;
};
void
sendMicData
();
void
initializeZid
();
std
::
string
zidFilename_
;
void
startReceiveThread
();
void
startSendThread
();
virtual
int
getIncrementForDTMF
()
const
;
AudioZrtpSendThread
rtpSendThread_
;
};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment