From 888e43b7d01020d7520f80d187d41052d168e103 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Wed, 18 Oct 2023 14:53:45 +0800 Subject: [PATCH] Fix warning when destroy connection in TURN mode --- src/ice/ice_agent.cpp | 18 ++++++++++++++++-- src/ice/ice_agent.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ice/ice_agent.cpp b/src/ice/ice_agent.cpp index 172c8ba..beea235 100644 --- a/src/ice/ice_agent.cpp +++ b/src/ice/ice_agent.cpp @@ -44,7 +44,7 @@ int IceAgent::CreateIceAgent(nice_cb_state_changed_t on_state_changed, agent_ = nice_agent_new_full(g_main_loop_get_context(gloop_), NICE_COMPATIBILITY_RFC5245, - (NiceAgentOption)(NICE_AGENT_OPTION_RELIABLE)); + (NiceAgentOption)(NICE_AGENT_OPTION_NONE)); if (agent_ == nullptr) { LOG_ERROR("Failed to create agent_"); @@ -73,6 +73,8 @@ int IceAgent::CreateIceAgent(nice_cb_state_changed_t on_state_changed, turn_port_, turn_username_.c_str(), turn_password_.c_str(), NICE_RELAY_TYPE_TURN_UDP); + g_object_set(agent_, "force-relay", true, NULL); + nice_agent_attach_recv(agent_, stream_id_, 1, g_main_loop_get_context(gloop_), on_recv_, user_ptr_); @@ -93,12 +95,23 @@ int IceAgent::CreateIceAgent(nice_cb_state_changed_t on_state_changed, return 0; } +void cb_closed(GObject *src, GAsyncResult *res, gpointer data) { + LOG_ERROR("cb_closed"); + NiceAgent *agent = NICE_AGENT(src); + g_debug("test-turn:%s: %p", G_STRFUNC, agent); + + *((gboolean *)data) = TRUE; +} + int IceAgent::DestroyIceAgent() { if (!nice_inited_) { LOG_ERROR("Nice agent has not been initialized"); return -1; } + nice_agent_remove_stream(agent_, stream_id_); + nice_agent_close_async(agent_, cb_closed, &agent_closed_); + destroyed_ = true; g_main_loop_quit(gloop_); @@ -127,7 +140,7 @@ char *IceAgent::GenerateLocalSdp() { } local_sdp_ = nice_agent_generate_local_sdp(agent_); - // LOG_INFO("Generate local sdp:[\n{}]", local_sdp_); + LOG_INFO("Generate local sdp:[\n{}]", local_sdp_); return local_sdp_; } @@ -220,6 +233,7 @@ int IceAgent::Send(const char *data, size_t size) { if (NiceComponentState::NICE_COMPONENT_STATE_READY != nice_agent_get_component_state(agent_, stream_id_, 1)) { + LOG_ERROR("Nice agent not ready"); return -1; } diff --git a/src/ice/ice_agent.h b/src/ice/ice_agent.h index 3c0758e..1bee321 100644 --- a/src/ice/ice_agent.h +++ b/src/ice/ice_agent.h @@ -66,6 +66,7 @@ class IceAgent { char* local_sdp_ = nullptr; NiceComponentState state_ = NiceComponentState::NICE_COMPONENT_STATE_LAST; bool destroyed_ = false; + gboolean agent_closed_ = false; nice_cb_state_changed_t on_state_changed_; nice_cb_candidate_t on_candidate_;