From 35d4f522c57a26222a82d5b42a76f5c99dbd3ad3 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Fri, 18 Oct 2024 17:15:33 +0800 Subject: [PATCH] [fix] stop threads when DestroyIceTransmission() called --- .../video/decode/aom/aom_av1_decoder.cpp | 3 +- src/pc/peer_connection.cpp | 1 + src/statistics/io_statistics.cpp | 18 +++++---- src/statistics/io_statistics.h | 1 + src/transmission/ice_transmission.cpp | 37 ++++++++++++------- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/media/video/decode/aom/aom_av1_decoder.cpp b/src/media/video/decode/aom/aom_av1_decoder.cpp index 6fa76c0..fb3acd7 100644 --- a/src/media/video/decode/aom/aom_av1_decoder.cpp +++ b/src/media/video/decode/aom/aom_av1_decoder.cpp @@ -83,7 +83,8 @@ int AomAv1Decoder::Decode( return -1; } - if (img_ = aom_codec_get_frame(&aom_av1_decoder_ctx_, &iter)) { + img_ = aom_codec_get_frame(&aom_av1_decoder_ctx_, &iter); + if (img_) { { aom_codec_frame_flags_t flags; ret = aom_codec_control(&aom_av1_decoder_ctx_, AOMD_GET_FRAME_FLAGS, diff --git a/src/pc/peer_connection.cpp b/src/pc/peer_connection.cpp index dcddbf3..94a7e24 100644 --- a/src/pc/peer_connection.cpp +++ b/src/pc/peer_connection.cpp @@ -956,6 +956,7 @@ void PeerConnection::ProcessIceWorkMsg(const IceWorkMsg &msg) { } case IceWorkMsg::Type::Destroy: { for (auto &user_id_it : ice_transmission_list_) { + LOG_ERROR("Destroy transmission"); user_id_it.second->DestroyIceTransmission(); } ice_transmission_list_.clear(); diff --git a/src/statistics/io_statistics.cpp b/src/statistics/io_statistics.cpp index cbd8ffb..8530aa4 100644 --- a/src/statistics/io_statistics.cpp +++ b/src/statistics/io_statistics.cpp @@ -1,5 +1,7 @@ #include "io_statistics.h" +#include "log.h" + IOStatistics::IOStatistics( std::function @@ -8,13 +10,7 @@ IOStatistics::IOStatistics( interval_ = 1000; } -IOStatistics::~IOStatistics() { - running_ = false; - cond_var_.notify_one(); - if (statistics_thread_.joinable()) { - statistics_thread_.join(); - } -} +IOStatistics::~IOStatistics() {} void IOStatistics::Process() { while (running_) { @@ -56,6 +52,14 @@ void IOStatistics::Start() { } } +void IOStatistics::Stop() { + running_ = false; + cond_var_.notify_one(); + if (statistics_thread_.joinable()) { + statistics_thread_.join(); + } +} + void IOStatistics::UpdateVideoInboundBytes(uint32_t bytes) { video_inbound_bytes_ += bytes; } diff --git a/src/statistics/io_statistics.h b/src/statistics/io_statistics.h index dd9c4eb..fb6fcd6 100644 --- a/src/statistics/io_statistics.h +++ b/src/statistics/io_statistics.h @@ -22,6 +22,7 @@ class IOStatistics { public: void Start(); + void Stop(); void UpdateVideoInboundBytes(uint32_t bytes); void UpdateVideoOutboundBytes(uint32_t bytes); diff --git a/src/transmission/ice_transmission.cpp b/src/transmission/ice_transmission.cpp index 6fdd321..7426b06 100644 --- a/src/transmission/ice_transmission.cpp +++ b/src/transmission/ice_transmission.cpp @@ -22,19 +22,7 @@ IceTransmission::IceTransmission( ice_ws_transport_(ice_ws_transmission), on_ice_status_change_(on_ice_status_change) {} -IceTransmission::~IceTransmission() { - if (rtp_video_sender_) { - rtp_video_sender_->Stop(); - } - - if (rtp_audio_sender_) { - rtp_audio_sender_->Stop(); - } - - if (rtp_data_sender_) { - rtp_data_sender_->Stop(); - } -} +IceTransmission::~IceTransmission() {} int IceTransmission::SetLocalCapabilities( bool use_trickle_ice, bool use_reliable_ice, bool enable_turn, @@ -351,6 +339,29 @@ int IceTransmission::DestroyIceTransmission() { if (on_ice_status_change_) { on_ice_status_change_("closed"); } + + if (ice_io_statistics_) { + ice_io_statistics_->Stop(); + } + + if (rtp_video_receiver_) { + rtp_video_receiver_->Stop(); + } + + if (rtp_video_sender_) { + rtp_video_sender_->Stop(); + } + + if (rtp_audio_sender_) { + rtp_audio_sender_->Stop(); + } + + if (rtp_data_sender_) { + rtp_data_sender_->Stop(); + } + + LOG_ERROR("threads stoped"); + return ice_agent_->DestroyIceAgent(); }