pjproject: add two patches from Asterisk 16.10.0
[feed/telephony.git] / libs / pjproject / patches / 0040-ICE-Add-callback-for-finding-valid-pair.patch
1 From 8b8199180766e3eab6014feaa64ccaedcdc12816 Mon Sep 17 00:00:00 2001
2 From: Ben Ford <bford@digium.com>
3 Date: Mon, 23 Dec 2019 11:11:13 -0600
4 Subject: [PATCH] ICE: Add callback for finding valid pair.
5
6 It's possible to start sending as soon as one valid pair is found during
7 ICE negotiation. The reason we would want to do this is because it is
8 possible for a delay to occur at the start of a call for up to 3 seconds
9 until ICE negotiation has actually completed. More information can be
10 found here:
11 https://bugs.chromium.org/p/chromium/issues/detail?id=1024096
12
13 This patch adds a callback once a valid pair is found that applications
14 can use to start sending to avoid this scenario. Since only one valid
15 pair is needed to start media, we only trigger the callback once.
16 ---
17 pjnath/include/pjnath/ice_session.h | 9 +++++++++
18 pjnath/src/pjnath/ice_session.c | 16 ++++++++++++++++
19 2 files changed, 25 insertions(+)
20
21 diff --git a/pjnath/include/pjnath/ice_session.h b/pjnath/include/pjnath/ice_session.h
22 index 15f0d04..8971220 100644
23 --- a/pjnath/include/pjnath/ice_session.h
24 +++ b/pjnath/include/pjnath/ice_session.h
25 @@ -468,6 +468,14 @@ typedef struct pj_ice_sess_cb
26 {
27 /**
28 * An optional callback that will be called by the ICE session when
29 + * a valid pair has been found during ICE negotiation.
30 + *
31 + * @param ice The ICE session.
32 + */
33 + void (*on_valid_pair)(pj_ice_sess *ice);
34 +
35 + /**
36 + * An optional callback that will be called by the ICE session when
37 * ICE negotiation has completed, successfully or with failure.
38 *
39 * @param ice The ICE session.
40 @@ -625,6 +633,7 @@ struct pj_ice_sess
41 pj_bool_t is_nominating; /**< Nominating stage */
42 pj_bool_t is_complete; /**< Complete? */
43 pj_bool_t is_destroying; /**< Destroy is called */
44 + pj_bool_t valid_pair_found; /**< First pair found */
45 pj_status_t ice_status; /**< Error status. */
46 pj_timer_entry timer; /**< ICE timer. */
47 pj_ice_sess_cb cb; /**< Callback. */
48 diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
49 index c51dba7..ed4138a 100644
50 --- a/pjnath/src/pjnath/ice_session.c
51 +++ b/pjnath/src/pjnath/ice_session.c
52 @@ -418,6 +418,8 @@ PJ_DEF(pj_status_t) pj_ice_sess_create(pj_stun_config *stun_cfg,
53
54 pj_list_init(&ice->early_check);
55
56 + ice->valid_pair_found = PJ_FALSE;
57 +
58 /* Done */
59 *p_ice = ice;
60
61 @@ -1348,6 +1350,20 @@ static pj_bool_t on_check_complete(pj_ice_sess *ice,
62 GET_CHECK_ID(&ice->clist, check),
63 (check->nominated ? " and nominated" : "")));
64
65 + {
66 + /* On the first valid pair, we call the callback, if present */
67 + if (ice->valid_pair_found == PJ_FALSE) {
68 + void (*on_valid_pair)(pj_ice_sess *ice);
69 +
70 + ice->valid_pair_found = PJ_TRUE;
71 + on_valid_pair = ice->cb.on_valid_pair;
72 +
73 + if (on_valid_pair) {
74 + (*on_valid_pair)(ice);
75 + }
76 + }
77 + }
78 +
79 }
80
81 /* 8.2. Updating States
82 --
83 2.7.4
84