From 5ca4ed53b2afc5902ca48377cf49a756181911c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sun, 11 Jun 2023 22:07:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=9E=90=E6=9E=84=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=8A=9B=E5=BC=82=E5=B8=B8=E5=AF=BC=E8=87=B4=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E9=97=AE=E9=A2=98=20(#2546)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MediaSource.cpp | 6 +++++- src/Player/PlayerProxy.cpp | 6 +++++- src/Pusher/MediaPusher.cpp | 3 +-- src/Record/HlsMaker.cpp | 4 +--- src/Record/HlsMediaSource.cpp | 6 +++++- src/Record/MP4Demuxer.cpp | 2 +- src/Rtp/RtpProcess.cpp | 6 +++++- src/Rtp/RtpSender.cpp | 6 +++++- srt/SrtTransportImp.cpp | 8 +++++--- 9 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index f2861153..6f3a62e4 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -124,7 +124,11 @@ MediaSource::MediaSource(const string &schema, const MediaTuple& tuple): _tuple( } MediaSource::~MediaSource() { - unregist(); + try { + unregist(); + } catch (std::exception &ex) { + WarnL << "Exception occurred: " << ex.what(); + } } const string& MediaSource::getSchema() const { diff --git a/src/Player/PlayerProxy.cpp b/src/Player/PlayerProxy.cpp index 36b4d850..2a319ff8 100644 --- a/src/Player/PlayerProxy.cpp +++ b/src/Player/PlayerProxy.cpp @@ -202,7 +202,11 @@ PlayerProxy::~PlayerProxy() { _timer.reset(); // 避免析构时, 忘记回调api请求 if (_on_play) { - _on_play(SockException(Err_shutdown, "player proxy close")); + try { + _on_play(SockException(Err_shutdown, "player proxy close")); + } catch (std::exception &ex) { + WarnL << "Exception occurred: " << ex.what(); + } _on_play = nullptr; } } diff --git a/src/Pusher/MediaPusher.cpp b/src/Pusher/MediaPusher.cpp index 865b4d2a..f0ea401b 100644 --- a/src/Pusher/MediaPusher.cpp +++ b/src/Pusher/MediaPusher.cpp @@ -31,8 +31,7 @@ MediaPusher::MediaPusher(const string &schema, MediaPusher(MediaSource::find(schema, vhost, app, stream), poller){ } -MediaPusher::~MediaPusher() { -} +MediaPusher::~MediaPusher() = default; static void setOnCreateSocket_l(const std::shared_ptr &delegate, const Socket::onCreateSocket &cb){ auto helper = dynamic_pointer_cast(delegate); diff --git a/src/Record/HlsMaker.cpp b/src/Record/HlsMaker.cpp index df4cb8de..bc6cf53d 100644 --- a/src/Record/HlsMaker.cpp +++ b/src/Record/HlsMaker.cpp @@ -22,9 +22,7 @@ HlsMaker::HlsMaker(float seg_duration, uint32_t seg_number, bool seg_keep) { _seg_keep = seg_keep; } -HlsMaker::~HlsMaker() { -} - +HlsMaker::~HlsMaker() = default; void HlsMaker::makeIndexFile(bool eof) { char file_content[1024]; diff --git a/src/Record/HlsMediaSource.cpp b/src/Record/HlsMediaSource.cpp index d6d4f4b4..f3fe516b 100644 --- a/src/Record/HlsMediaSource.cpp +++ b/src/Record/HlsMediaSource.cpp @@ -46,7 +46,11 @@ HlsCookieData::~HlsCookieData() { GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); uint64_t bytes = _bytes.load(); if (bytes >= iFlowThreshold * 1024) { - NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _info, bytes, duration, true, static_cast(*_sock_info)); + try { + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _info, bytes, duration, true, static_cast(*_sock_info)); + } catch (std::exception &ex) { + WarnL << "Exception occurred: " << ex.what(); + } } } } diff --git a/src/Record/MP4Demuxer.cpp b/src/Record/MP4Demuxer.cpp index a1c657fd..a1bbd34c 100644 --- a/src/Record/MP4Demuxer.cpp +++ b/src/Record/MP4Demuxer.cpp @@ -21,7 +21,7 @@ using namespace std; namespace mediakit { -MP4Demuxer::MP4Demuxer() {} +MP4Demuxer::MP4Demuxer() = default; MP4Demuxer::~MP4Demuxer() { closeMP4(); diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 9700e09c..741cc4b1 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -66,7 +66,11 @@ RtpProcess::~RtpProcess() { //流量统计事件广播 GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); if (_total_bytes >= iFlowThreshold * 1024) { - NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _total_bytes, duration, false, static_cast(*this)); + try { + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _total_bytes, duration, false, static_cast(*this)); + } catch (std::exception &ex) { + WarnL << "Exception occurred: " << ex.what(); + } } } diff --git a/src/Rtp/RtpSender.cpp b/src/Rtp/RtpSender.cpp index a15884f0..a102d5e2 100644 --- a/src/Rtp/RtpSender.cpp +++ b/src/Rtp/RtpSender.cpp @@ -28,7 +28,11 @@ RtpSender::RtpSender(EventPoller::Ptr poller) { } RtpSender::~RtpSender() { - flush(); + try { + flush(); + } catch (std::exception &ex) { + WarnL << "Exception occurred: " << ex.what(); + } } void RtpSender::startSend(const MediaSourceEvent::SendRtpArgs &args, const function &cb){ diff --git a/srt/SrtTransportImp.cpp b/srt/SrtTransportImp.cpp index 91ae7488..c3c18c5d 100644 --- a/srt/SrtTransportImp.cpp +++ b/srt/SrtTransportImp.cpp @@ -16,9 +16,11 @@ SrtTransportImp::~SrtTransportImp() { // 流量统计事件广播 GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); if (_total_bytes >= iFlowThreshold * 1024) { - NoticeCenter::Instance().emitEvent( - Broadcast::kBroadcastFlowReport, _media_info, _total_bytes, duration, !_is_pusher, - static_cast(*this)); + try { + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _total_bytes, duration, !_is_pusher, static_cast(*this)); + } catch (std::exception &ex) { + WarnL << "Exception occurred: " << ex.what(); + } } }