Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
mediastreamer2
Commits
fdb11bed
Commit
fdb11bed
authored
Jul 05, 2012
by
Ghislain MARY
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Form ICE candidate pairs.
parent
677ae278
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
4 deletions
+69
-4
include/mediastreamer2/ice.h
include/mediastreamer2/ice.h
+5
-0
src/ice.c
src/ice.c
+62
-4
tests/mediastream.c
tests/mediastream.c
+2
-0
No files found.
include/mediastreamer2/ice.h
View file @
fdb11bed
...
...
@@ -64,6 +64,7 @@ typedef struct {
IceCandidate
*
local
;
IceCandidate
*
remote
;
IceCandidatePairState
state
;
uint64_t
priority
;
bool_t
is_default
;
bool_t
is_valid
;
bool_t
is_nominated
;
...
...
@@ -95,8 +96,12 @@ void ice_handle_stun_packet(IceCheckList *cl, RtpSession *session, mblk_t *m);
void
ice_gather_candidates
(
IceCheckList
*
cl
);
void
ice_pair_candidates
(
IceCheckList
*
cl
);
void
ice_dump_candidates
(
IceCheckList
*
cl
);
void
ice_dump_candidate_pairs
(
IceCheckList
*
cl
);
#ifdef __cplusplus
}
#endif
...
...
src/ice.c
View file @
fdb11bed
...
...
@@ -58,6 +58,11 @@ static void ice_check_list_init(IceCheckList *cl)
cl
->
state
=
ICL_Running
;
}
static
void
ice_free_candidate_pair
(
IceCandidatePair
*
pair
)
{
ms_free
(
pair
);
}
static
void
ice_free_candidate
(
IceCandidate
*
candidate
)
{
ms_free
(
candidate
);
...
...
@@ -123,8 +128,10 @@ IceCheckList * ice_check_list_new(void)
void
ice_check_list_destroy
(
IceCheckList
*
cl
)
{
ms_list_for_each
(
cl
->
pairs
,
(
void
(
*
)(
void
*
))
ice_free_candidate_pair
);
ms_list_for_each
(
cl
->
remote_candidates
,
(
void
(
*
)(
void
*
))
ice_free_candidate
);
ms_list_for_each
(
cl
->
local_candidates
,
(
void
(
*
)(
void
*
))
ice_free_candidate
);
ms_list_free
(
cl
->
pairs
);
ms_list_free
(
cl
->
remote_candidates
);
ms_list_free
(
cl
->
local_candidates
);
ms_free
(
cl
);
...
...
@@ -160,16 +167,67 @@ void ice_gather_candidates(IceCheckList *cl)
//TODO
}
static
void
ice_dump_candidate
(
IceCandidate
*
candidate
)
static
void
ice_compute_pair_priority
(
IceCandidatePair
*
pair
)
{
/* Use formula defined in 5.7.2 to compute pair priority. */
// TODO: Use controlling agent for G and controlled agent for D. For the moment use local candidate for G and remote candidate for D.
uint64_t
G
=
pair
->
local
->
priority
;
uint64_t
D
=
pair
->
remote
->
priority
;
pair
->
priority
=
(
MIN
(
G
,
D
)
<<
32
)
|
(
MAX
(
G
,
D
)
<<
1
)
|
(
G
>
D
?
1
:
0
);
}
void
ice_pair_candidates
(
IceCheckList
*
cl
)
{
MSList
*
local_list
=
cl
->
local_candidates
;
MSList
*
remote_list
;
IceCandidatePair
*
pair
;
IceCandidate
*
local_candidate
;
IceCandidate
*
remote_candidate
;
while
(
local_list
!=
NULL
)
{
remote_list
=
cl
->
remote_candidates
;
while
(
remote_list
!=
NULL
)
{
local_candidate
=
(
IceCandidate
*
)
local_list
->
data
;
remote_candidate
=
(
IceCandidate
*
)
remote_list
->
data
;
if
(
local_candidate
->
componentID
==
remote_candidate
->
componentID
)
{
pair
=
ms_new
(
IceCandidatePair
,
1
);
pair
->
local
=
local_candidate
;
pair
->
remote
=
remote_candidate
;
ice_compute_pair_priority
(
pair
);
// TODO: Handle state, is_default, is_valid, is_nominated.
cl
->
pairs
=
ms_list_append
(
cl
->
pairs
,
pair
);
}
remote_list
=
ms_list_next
(
remote_list
);
}
local_list
=
ms_list_next
(
local_list
);
}
}
static
void
ice_dump_candidate
(
IceCandidate
*
candidate
,
const
char
*
const
prefix
)
{
ms_debug
(
"
\t
type=%s ip=%s port=%u, componentID=%d priority=%u"
,
ms_debug
(
"
%s
type=%s ip=%s port=%u, componentID=%d priority=%u"
,
prefix
,
candidate_type_values
[
candidate
->
type
],
candidate
->
taddr
.
ip
,
candidate
->
taddr
.
port
,
candidate
->
componentID
,
candidate
->
priority
);
}
void
ice_dump_candidates
(
IceCheckList
*
cl
)
{
ms_debug
(
"Local candidates:"
);
ms_list_for_each
(
cl
->
local_candidates
,
(
void
(
*
)(
void
*
))
ice_dump_candidate
);
ms_list_for_each
2
(
cl
->
local_candidates
,
(
void
(
*
)(
void
*
,
void
*
))
ice_dump_candidate
,
"
\t
"
);
ms_debug
(
"Remote candidates:"
);
ms_list_for_each
(
cl
->
remote_candidates
,
(
void
(
*
)(
void
*
))
ice_dump_candidate
);
ms_list_for_each2
(
cl
->
remote_candidates
,
(
void
(
*
)(
void
*
,
void
*
))
ice_dump_candidate
,
"
\t
"
);
}
static
void
ice_dump_candidate_pair
(
IceCandidatePair
*
pair
,
int
*
i
)
{
ms_debug
(
"
\t
%d: priority=%llu"
,
*
i
,
pair
->
priority
);
ice_dump_candidate
(
pair
->
local
,
"
\t\t
Local: "
);
ice_dump_candidate
(
pair
->
remote
,
"
\t\t
Remote: "
);
(
*
i
)
++
;
}
void
ice_dump_candidate_pairs
(
IceCheckList
*
cl
)
{
int
i
=
1
;
ms_debug
(
"Candidate pairs:"
);
ms_list_for_each2
(
cl
->
pairs
,
(
void
(
*
)(
void
*
,
void
*
))
ice_dump_candidate_pair
,
(
void
*
)
&
i
);
}
tests/mediastream.c
View file @
fdb11bed
...
...
@@ -615,7 +615,9 @@ void setup_media_streams(MediastreamDatas* args) {
ice_add_remote_candidate
(
args
->
audio
->
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
+
1
,
2
,
0
);
}
}
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
);
if
(
args
->
audio
)
{
if
(
args
->
el
)
{
...
...
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