From e021276c82c20b4f79c9d7e5bc3d88a7a3611747 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Thu, 19 Sep 2024 14:39:42 -0400 Subject: [PATCH] Don't clear candidates on Answerer set_remote_description This allows add_ice_candidate to work when answering --- src/agent.c | 3 --- src/peer_connection.c | 10 ++++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/agent.c b/src/agent.c index f2c3aa9..788e841 100644 --- a/src/agent.c +++ b/src/agent.c @@ -277,8 +277,6 @@ void agent_gather_candidate(Agent* agent, const char* urls, const char* username } void agent_get_local_description(Agent* agent, char* description, int length) { - int ncandidates = 0; - memset(description, 0, length); memset(agent->local_ufrag, 0, sizeof(agent->local_ufrag)); memset(agent->local_upwd, 0, sizeof(agent->local_upwd)); @@ -287,7 +285,6 @@ void agent_get_local_description(Agent* agent, char* description, int length) { utils_random_string(agent->local_upwd, 24); snprintf(description, length, "a=ice-ufrag:%s\r\na=ice-pwd:%s\r\n", agent->local_ufrag, agent->local_upwd); - ncandidates = agent->local_candidates_count; for (int i = 0; i < agent->local_candidates_count; i++) { ice_candidate_to_description(&agent->local_candidates[i], description + strlen(description), length - strlen(description)); diff --git a/src/peer_connection.c b/src/peer_connection.c index e68a354..99b405f 100644 --- a/src/peer_connection.c +++ b/src/peer_connection.c @@ -256,7 +256,7 @@ static char* peer_connection_dtls_role_setup_value(DtlsSrtpRole d) { return d == DTLS_SRTP_ROLE_SERVER ? "a=setup:passive" : "a=setup:active"; } -static void peer_connection_state_new(PeerConnection* pc, DtlsSrtpRole role) { +static void peer_connection_state_new(PeerConnection* pc, DtlsSrtpRole role, int isOfferer) { char* description = (char*)pc->temp_buf; memset(pc->temp_buf, 0, sizeof(pc->temp_buf)); @@ -268,7 +268,9 @@ static void peer_connection_state_new(PeerConnection* pc, DtlsSrtpRole role) { pc->sctp.connected = 0; - agent_clear_candidates(&pc->agent); + if (isOfferer) { + agent_clear_candidates(&pc->agent); + } agent_gather_candidate(&pc->agent, NULL, NULL, NULL); // host address for (int i = 0; i < sizeof(pc->config.ice_servers) / sizeof(pc->config.ice_servers[0]); ++i) { @@ -346,7 +348,7 @@ int peer_connection_loop(PeerConnection* pc) { case PEER_CONNECTION_NEW: if (!pc->b_local_description_created) { - peer_connection_state_new(pc, DTLS_SRTP_ROLE_SERVER); + peer_connection_state_new(pc, DTLS_SRTP_ROLE_SERVER, 1); } break; @@ -484,7 +486,7 @@ void peer_connection_set_remote_description(PeerConnection* pc, const char* sdp_ } if (!pc->b_local_description_created) { - peer_connection_state_new(pc, role); + peer_connection_state_new(pc, role, 0); } agent_set_remote_description(&pc->agent, (char*)sdp_text);