mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-02 20:08:17 +00:00
RTP/ICE: Send on first valid pair.
When handling ICE negotiations, it's possible that there can be a delay between STUN binding requests which in turn will cause a delay in ICE completion, preventing media from flowing. It should be possible to send media when there is at least one valid pair, preventing this scenario from occurring. A change was added to PJPROJECT that adds an optional callback (on_valid_pair) that will be called when the first valid pair is found during ICE negotiation. Asterisk uses this to start the DTLS handshake, allowing media to flow. It will only be called once, either on the first valid pair, or when ICE negotiation is complete. ASTERISK-28716 Change-Id: Ia7b68c34f06d2a1d91c5ed51627b66fd0363d867
This commit is contained in:
committed by
Benjamin Keith Ford
parent
1fc1336b2c
commit
168637cc0c
@@ -447,6 +447,7 @@ struct ast_rtp {
|
||||
struct ao2_container *ice_proposed_remote_candidates; /*!< Incoming remote ICE candidates for new session */
|
||||
struct ast_sockaddr ice_original_rtp_addr; /*!< rtp address that ICE started on first session */
|
||||
unsigned int ice_num_components; /*!< The number of ICE components */
|
||||
unsigned int ice_media_started:1; /*!< ICE media has started, either on a valid pair or on ICE completion */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_OPENSSL) && (OPENSSL_VERSION_NUMBER >= 0x10001000L) && !defined(OPENSSL_NO_SRTP)
|
||||
@@ -968,6 +969,8 @@ static int ice_reset_session(struct ast_rtp_instance *instance)
|
||||
}
|
||||
}
|
||||
|
||||
rtp->ice_media_started = 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2527,13 +2530,14 @@ static void dtls_perform_setup(struct dtls_details *dtls)
|
||||
#ifdef HAVE_PJPROJECT
|
||||
static void rtp_learning_start(struct ast_rtp *rtp);
|
||||
|
||||
/* PJPROJECT ICE callback */
|
||||
static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
|
||||
/* Handles start of media during ICE negotiation or completion */
|
||||
static void ast_rtp_ice_start_media(pj_ice_sess *ice, pj_status_t status)
|
||||
{
|
||||
struct ast_rtp_instance *instance = ice->user_data;
|
||||
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
|
||||
|
||||
ao2_lock(instance);
|
||||
|
||||
if (status == PJ_SUCCESS) {
|
||||
struct ast_sockaddr remote_address;
|
||||
|
||||
@@ -2552,6 +2556,11 @@ static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
|
||||
}
|
||||
|
||||
#if defined(HAVE_OPENSSL) && (OPENSSL_VERSION_NUMBER >= 0x10001000L) && !defined(OPENSSL_NO_SRTP)
|
||||
/* If we've already started media, no need to do all of this again */
|
||||
if (rtp->ice_media_started) {
|
||||
ao2_unlock(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
ast_debug(3, "ast_rtp_on_ice_complete (%p) - perform DTLS\n", rtp);
|
||||
|
||||
@@ -2574,6 +2583,8 @@ static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
|
||||
}
|
||||
#endif
|
||||
|
||||
rtp->ice_media_started = 1;
|
||||
|
||||
if (!strictrtp) {
|
||||
ao2_unlock(instance);
|
||||
return;
|
||||
@@ -2584,6 +2595,20 @@ static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
|
||||
ao2_unlock(instance);
|
||||
}
|
||||
|
||||
#ifdef HAVE_PJPROJECT_ON_VALID_ICE_PAIR_CALLBACK
|
||||
/* PJPROJECT ICE optional callback */
|
||||
static void ast_rtp_on_valid_pair(pj_ice_sess *ice)
|
||||
{
|
||||
ast_rtp_ice_start_media(ice, PJ_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* PJPROJECT ICE callback */
|
||||
static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
|
||||
{
|
||||
ast_rtp_ice_start_media(ice, status);
|
||||
}
|
||||
|
||||
/* PJPROJECT ICE callback */
|
||||
static void ast_rtp_on_ice_rx_data(pj_ice_sess *ice, unsigned comp_id, unsigned transport_id, void *pkt, pj_size_t size, const pj_sockaddr_t *src_addr, unsigned src_addr_len)
|
||||
{
|
||||
@@ -2640,6 +2665,9 @@ static pj_status_t ast_rtp_on_ice_tx_pkt(pj_ice_sess *ice, unsigned comp_id, uns
|
||||
|
||||
/* ICE Session interface declaration */
|
||||
static pj_ice_sess_cb ast_rtp_ice_sess_cb = {
|
||||
#ifdef HAVE_PJPROJECT_ON_VALID_ICE_PAIR_CALLBACK
|
||||
.on_valid_pair = ast_rtp_on_valid_pair,
|
||||
#endif
|
||||
.on_ice_complete = ast_rtp_on_ice_complete,
|
||||
.on_rx_data = ast_rtp_on_ice_rx_data,
|
||||
.on_tx_pkt = ast_rtp_on_ice_tx_pkt,
|
||||
|
||||
Reference in New Issue
Block a user