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
0bde5fde
Commit
0bde5fde
authored
Aug 15, 2013
by
Tristan Matthews
Browse files
* #28529: sip: add members for RTP port ranges
parent
5e80aac6
Changes
3
Hide whitespace changes
Inline
Side-by-side
daemon/src/sip/sipaccount.cpp
View file @
0bde5fde
...
...
@@ -115,6 +115,8 @@ SIPAccount::SIPAccount(const std::string& accountID)
,
receivedParameter_
(
""
)
,
rPort_
(
-
1
)
,
via_addr_
()
,
audioPortRange_
(
16384
,
32766
)
,
videoPortRange_
(
49152
,
65534
)
{
via_addr_
.
host
.
ptr
=
0
;
via_addr_
.
host
.
slen
=
0
;
...
...
@@ -1299,3 +1301,27 @@ bool SIPAccount::matches(const std::string &userName, const std::string &server,
}
else
return
false
;
}
namespace
{
// returns even number in range [lower, upper]
unsigned
int
getRandomEvenNumber
(
const
std
::
pair
<
unsigned
,
unsigned
>
&
range
)
{
const
unsigned
halfUpper
=
range
.
second
*
0.5
;
const
unsigned
halfLower
=
range
.
first
*
0.5
;
return
2
*
(
halfLower
+
rand
()
%
(
halfUpper
-
halfLower
+
1
));
}
}
unsigned
SIPAccount
::
generateAudioPort
()
const
{
return
getRandomEvenNumber
(
audioPortRange_
);
}
#ifdef SFL_VIDEO
unsigned
SIPAccount
::
generateVideoPort
()
const
{
return
getRandomEvenNumber
(
videoPortRange_
);
}
#endif
daemon/src/sip/sipaccount.h
View file @
0bde5fde
...
...
@@ -515,6 +515,11 @@ class SIPAccount : public Account {
/* Returns true if the username and/or hostname match this account */
bool
matches
(
const
std
::
string
&
username
,
const
std
::
string
&
hostname
,
pjsip_endpoint
*
endpt
,
pj_pool_t
*
pool
)
const
;
unsigned
generateAudioPort
()
const
;
#ifdef SFL_VIDEO
unsigned
generateVideoPort
()
const
;
#endif
private:
NON_COPYABLE
(
SIPAccount
);
...
...
@@ -762,6 +767,18 @@ class SIPAccount : public Account {
* Optional: via_addr construct from received parameters
*/
pjsip_host_port
via_addr_
;
/**
* Port range for audio RTP ports
*/
std
::
pair
<
unsigned
,
unsigned
>
audioPortRange_
;
#ifdef SFL_VIDEO
/**
* Port range for video RTP ports
*/
std
::
pair
<
unsigned
,
unsigned
>
videoPortRange_
;
#endif
};
#endif
daemon/src/sip/sipvoiplink.cpp
View file @
0bde5fde
...
...
@@ -2349,16 +2349,6 @@ void transfer_client_cb(pjsip_evsub *sub, pjsip_event *event)
}
}
namespace
{
// returns even number in range [lower, upper]
unsigned
int
getRandomEvenNumber
(
int
lower
,
int
upper
)
{
const
unsigned
halfUpper
=
upper
*
0.5
;
const
unsigned
halfLower
=
lower
*
0.5
;
return
2
*
(
halfLower
+
rand
()
%
(
halfUpper
-
halfLower
+
1
));
}
}
void
setCallMediaLocal
(
SIPCall
*
call
,
const
std
::
string
&
localIP
)
{
std
::
string
account_id
(
call
->
getAccountId
());
...
...
@@ -2369,7 +2359,7 @@ void setCallMediaLocal(SIPCall* call, const std::string &localIP)
// Reference: http://www.cs.columbia.edu/~hgs/rtp/faq.html#ports
// We only want to set ports to new values if they haven't been set
if
(
call
->
getLocalAudioPort
()
==
0
)
{
const
unsigned
callLocalAudioPort
=
getRandomEvenNumber
(
16384
,
32766
);
const
unsigned
callLocalAudioPort
=
account
->
generateAudioPort
(
);
call
->
setLocalAudioPort
(
callLocalAudioPort
);
call
->
getLocalSDP
()
->
setLocalPublishedAudioPort
(
callLocalAudioPort
);
}
...
...
@@ -2381,7 +2371,7 @@ void setCallMediaLocal(SIPCall* call, const std::string &localIP)
// https://projects.savoirfairelinux.com/issues/17498
unsigned
int
callLocalVideoPort
;
do
callLocalVideoPort
=
getRandomEvenNumber
(
49152
,
65534
);
callLocalVideoPort
=
account
->
generateVideoPort
(
);
while
(
call
->
getLocalAudioPort
()
==
callLocalVideoPort
);
call
->
setLocalVideoPort
(
callLocalVideoPort
);
...
...
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