From 21737c354ac45889b9e5d64474cf4c66cfc2131d Mon Sep 17 00:00:00 2001 From: dijunkun Date: Wed, 27 Nov 2024 22:15:45 +0800 Subject: [PATCH] [fix] fix crash: ice worker still has IceWorkMsg::Type::Destroy msg which has not been processed when try to stop ice worker --- src/ice/ice_agent.cpp | 2 +- src/pc/peer_connection.cpp | 29 ++++++++++++----------------- src/pc/peer_connection.h | 7 +++++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/ice/ice_agent.cpp b/src/ice/ice_agent.cpp index e2a24a7..ab43388 100644 --- a/src/ice/ice_agent.cpp +++ b/src/ice/ice_agent.cpp @@ -7,7 +7,7 @@ #include "log.h" -#define SAVE_IO_STREAM +// #define SAVE_IO_STREAM IceAgent::IceAgent(bool offer_peer, bool use_trickle_ice, bool use_reliable_ice, bool enable_turn, bool force_turn, std::string &stun_ip, diff --git a/src/pc/peer_connection.cpp b/src/pc/peer_connection.cpp index db2cf85..27dfcc2 100644 --- a/src/pc/peer_connection.cpp +++ b/src/pc/peer_connection.cpp @@ -162,11 +162,10 @@ int PeerConnection::Init(PeerConnectionParams params, LOG_INFO( "Ice failed, destroy ice agent and rereate it with TURN enabled"); - IceWorkMsg msg; - msg.type = IceWorkMsg::Type::Destroy; - PushIceWorkMsg(msg); + ReleaseAllIceTransmission(); if (offer_peer_) { + IceWorkMsg msg; msg.type = IceWorkMsg::Type::UserIdList; msg.transmission_id = remote_transmission_id_; msg.user_id_list = user_id_list_; @@ -277,9 +276,7 @@ int PeerConnection::NegotiationFailed() { user_id_, remote_user_id_, local_transmission_id_); } - IceWorkMsg msg; - msg.type = IceWorkMsg::Type::Destroy; - PushIceWorkMsg(msg); + ReleaseAllIceTransmission(); return 0; } @@ -302,10 +299,16 @@ int PeerConnection::Leave(const std::string &transmission_id) { is_ice_transmission_ready_[user_id_] = false; leave_ = true; - IceWorkMsg msg; - msg.type = IceWorkMsg::Type::Destroy; - PushIceWorkMsg(msg); + ReleaseAllIceTransmission(); + return 0; +} +int PeerConnection::ReleaseAllIceTransmission() { + for (auto &user_id_it : ice_transmission_list_) { + user_id_it.second->DestroyIceTransmission(); + } + ice_transmission_list_.clear(); + is_ice_transmission_ready_.clear(); return 0; } @@ -723,14 +726,6 @@ void PeerConnection::ProcessIceWorkMsg(const IceWorkMsg &msg) { } break; } - case IceWorkMsg::Type::Destroy: { - for (auto &user_id_it : ice_transmission_list_) { - user_id_it.second->DestroyIceTransmission(); - } - ice_transmission_list_.clear(); - is_ice_transmission_ready_.clear(); - break; - } default: { break; } diff --git a/src/pc/peer_connection.h b/src/pc/peer_connection.h index 6b650fc..9cc6872 100644 --- a/src/pc/peer_connection.h +++ b/src/pc/peer_connection.h @@ -68,8 +68,7 @@ struct IceWorkMsg { UserLeaveTransmission, Offer, Answer, - NewCandidate, - Destroy + NewCandidate }; Type type; @@ -97,6 +96,8 @@ class PeerConnection { int Leave(const std::string &transmission_id); + int ReleaseAllIceTransmission(); + int Destroy(); SignalStatus GetSignalStatus(); @@ -201,7 +202,9 @@ class PeerConnection { std::atomic ice_worker_running_{true}; std::queue ice_work_msg_queue_; std::condition_variable ice_work_cv_; + std::condition_variable empty_notify_cv_; std::mutex ice_work_mutex_; + std::mutex empty_notify_mutex_; }; #endif \ No newline at end of file