Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
mediastreamer2
Commits
99ccaf5f
Commit
99ccaf5f
authored
Jul 06, 2012
by
Ghislain MARY
Browse files
Choose default ICE candidates.
parent
fb68f79c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
4 deletions
+59
-4
include/mediastreamer2/ice.h
include/mediastreamer2/ice.h
+3
-0
src/ice.c
src/ice.c
+55
-4
tests/mediastream.c
tests/mediastream.c
+1
-0
No files found.
include/mediastreamer2/ice.h
View file @
99ccaf5f
...
...
@@ -59,6 +59,7 @@ typedef struct _IceCandidate {
uint32_t
priority
;
uint16_t
componentID
;
/**< component ID between 1 and 256: usually 1 for RTP component and 2 for RTCP component */
struct
_IceCandidate
*
base
;
bool_t
is_default
;
// TODO: relatedAddr
}
IceCandidate
;
...
...
@@ -105,6 +106,8 @@ void ice_gather_candidates(IceCheckList *cl);
void
ice_compute_candidate_foundations
(
IceCheckList
*
cl
);
void
ice_choose_default_candidates
(
IceCheckList
*
cl
);
void
ice_pair_candidates
(
IceCheckList
*
cl
);
/**
...
...
src/ice.c
View file @
99ccaf5f
...
...
@@ -33,6 +33,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define ICE_MAX_NB_CANDIDATES 10
#define ICE_MAX_NB_CANDIDATE_PAIRS (ICE_MAX_NB_CANDIDATES*ICE_MAX_NB_CANDIDATES)
#define ICE_MIN_COMPONENTID 1
#define ICE_MAX_COMPONENTID 256
static
const
char
*
const
candidate_type_values
[]
=
{
"host"
,
/* ICT_HostCandidate */
...
...
@@ -103,6 +106,7 @@ static IceCandidate * ice_add_candidate(MSList **list, const char *type, const c
candidate
->
taddr
.
port
=
port
;
candidate
->
type
=
candidate_type
;
candidate
->
componentID
=
componentID
;
candidate
->
is_default
=
FALSE
;
switch
(
candidate
->
type
)
{
case
ICT_HostCandidate
:
...
...
@@ -274,6 +278,48 @@ void ice_compute_candidate_foundations(IceCheckList *cl)
ms_list_for_each2
(
cl
->
local_candidates
,
(
void
(
*
)(
void
*
,
void
*
))
ice_compute_candidate_foundation
,
cl
);
}
typedef
struct
_TypeAndComponentID
{
IceCandidateType
type
;
uint16_t
componentID
;
}
TypeAndComponentID
;
static
int
ice_find_candidate_from_type_and_componentID
(
IceCandidate
*
candidate
,
TypeAndComponentID
*
tc
)
{
return
!
((
candidate
->
type
==
tc
->
type
)
&&
(
candidate
->
componentID
==
tc
->
componentID
));
}
static
void
ice_choose_local_or_remote_default_candidates
(
IceCheckList
*
cl
,
MSList
*
list
)
{
TypeAndComponentID
tc
;
MSList
*
l
;
int
i
;
/* Choose the default candidate for each componentID as defined in 4.1.4. */
for
(
i
=
ICE_MIN_COMPONENTID
;
i
<=
ICE_MAX_COMPONENTID
;
i
++
)
{
tc
.
componentID
=
i
;
tc
.
type
=
ICT_RelayedCandidate
;
l
=
ms_list_find_custom
(
list
,
(
MSCompareFunc
)
ice_find_candidate_from_type_and_componentID
,
&
tc
);
if
(
l
==
NULL
)
{
tc
.
type
=
ICT_ServerReflexiveCandidate
;
l
=
ms_list_find_custom
(
list
,
(
MSCompareFunc
)
ice_find_candidate_from_type_and_componentID
,
&
tc
);
}
if
(
l
==
NULL
)
{
tc
.
type
=
ICT_HostCandidate
;
l
=
ms_list_find_custom
(
list
,
(
MSCompareFunc
)
ice_find_candidate_from_type_and_componentID
,
&
tc
);
}
if
(
l
!=
NULL
)
{
IceCandidate
*
candidate
=
(
IceCandidate
*
)
l
->
data
;
candidate
->
is_default
=
TRUE
;
}
}
}
void
ice_choose_default_candidates
(
IceCheckList
*
cl
)
{
ice_choose_local_or_remote_default_candidates
(
cl
,
cl
->
local_candidates
);
ice_choose_local_or_remote_default_candidates
(
cl
,
cl
->
remote_candidates
);
}
void
ice_pair_candidates
(
IceCheckList
*
cl
)
{
MSList
*
local_list
=
cl
->
local_candidates
;
...
...
@@ -295,8 +341,12 @@ void ice_pair_candidates(IceCheckList *cl)
pair
->
local
=
local_candidate
;
pair
->
remote
=
remote_candidate
;
pair
->
state
=
ICP_Frozen
;
pair
->
is_default
=
FALSE
;
pair
->
is_nominated
=
FALSE
;
if
((
pair
->
local
->
is_default
==
TRUE
)
&&
(
pair
->
remote
->
is_default
==
TRUE
))
pair
->
is_default
=
TRUE
;
else
pair
->
is_default
=
FALSE
;
ice_compute_pair_priority
(
pair
);
// TODO: Handle is_
default, is_valid, is_nominate
d.
// TODO: Handle is_
vali
d.
cl
->
pairs
=
ms_list_insert_sorted
(
cl
->
pairs
,
pair
,
(
MSCompareFunc
)
ice_compare_pair_priorities
);
}
remote_list
=
ms_list_next
(
remote_list
);
...
...
@@ -344,8 +394,9 @@ void ice_set_base_for_srflx_candidates(IceCheckList *cl)
static
void
ice_dump_candidate
(
IceCandidate
*
candidate
,
const
char
*
const
prefix
)
{
ms_debug
(
"%s[%p]: type=%s ip=%s port=%u componentID=%d priority=%u foundation=%s base=%p"
,
prefix
,
candidate
,
candidate_type_values
[
candidate
->
type
],
candidate
->
taddr
.
ip
,
candidate
->
taddr
.
port
,
ms_debug
(
"%s[%p]: %stype=%s ip=%s port=%u componentID=%d priority=%u foundation=%s base=%p"
,
prefix
,
candidate
,
((
candidate
->
is_default
==
TRUE
)
?
"* "
:
" "
),
candidate_type_values
[
candidate
->
type
],
candidate
->
taddr
.
ip
,
candidate
->
taddr
.
port
,
candidate
->
componentID
,
candidate
->
priority
,
candidate
->
foundation
,
candidate
->
base
);
}
...
...
@@ -359,7 +410,7 @@ void ice_dump_candidates(IceCheckList *cl)
static
void
ice_dump_candidate_pair
(
IceCandidatePair
*
pair
,
int
*
i
)
{
ms_debug
(
"
\t
%d [%p]: priority=%llu"
,
*
i
,
pair
,
pair
->
priority
);
ms_debug
(
"
\t
%d [%p]:
%s
priority=%llu"
,
*
i
,
pair
,
((
pair
->
is_default
==
TRUE
)
?
"* "
:
" "
),
pair
->
priority
);
ice_dump_candidate
(
pair
->
local
,
"
\t\t
Local: "
);
ice_dump_candidate
(
pair
->
remote
,
"
\t\t
Remote: "
);
(
*
i
)
++
;
...
...
tests/mediastream.c
View file @
99ccaf5f
...
...
@@ -620,6 +620,7 @@ void setup_media_streams(MediastreamDatas* args) {
ice_add_remote_candidate
(
args
->
audio
->
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
+
1
,
2
,
0
,
foundation
);
}
}
ice_choose_default_candidates
(
args
->
audio
->
ice_check_list
);
ice_pair_candidates
(
args
->
audio
->
ice_check_list
);
ice_dump_candidates
(
args
->
audio
->
ice_check_list
);
ice_dump_candidate_pairs
(
args
->
audio
->
ice_check_list
);
...
...
Write
Preview
Markdown
is supported
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