From a09de23271c00ec0d92a6d737ecc225663800119 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 16 Jun 2021 10:14:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B0=83=E7=94=A8mk=5Fmedia?= =?UTF-8?q?=5Fstop=5Fsend=5Frtp=E5=87=BD=E6=95=B0=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/source/mk_media.cpp | 4 ++-- src/Common/MediaSource.h | 11 ++++++----- src/Common/MultiMediaSourceMuxer.cpp | 14 ++++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/api/source/mk_media.cpp b/api/source/mk_media.cpp index 8c20c87d..395cc17e 100755 --- a/api/source/mk_media.cpp +++ b/api/source/mk_media.cpp @@ -193,7 +193,7 @@ API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_u assert(ctx && dst_url && ssrc); MediaHelper::Ptr* obj = (MediaHelper::Ptr*) ctx; //sender参数无用 - (*obj)->getChannel()->startSendRtp(*(MediaSource *) 1, dst_url, dst_port, ssrc, is_udp, 0, [cb, user_data](uint16_t local_port, const SockException &ex){ + (*obj)->getChannel()->startSendRtp(*MediaSource::NullMediaSource, dst_url, dst_port, ssrc, is_udp, 0, [cb, user_data](uint16_t local_port, const SockException &ex){ if (cb) { cb(user_data, local_port, ex.getErrCode(), ex.what()); } @@ -204,5 +204,5 @@ API_EXPORT int API_CALL mk_media_stop_send_rtp(mk_media ctx){ assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; //sender参数无用 - return (*obj)->getChannel()->stopSendRtp(*(MediaSource *) 1, ""); + return (*obj)->getChannel()->stopSendRtp(*MediaSource::NullMediaSource, ""); } \ No newline at end of file diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index b85415fc..5ca1d5aa 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -191,11 +191,12 @@ private: */ class MediaSource: public TrackSource, public enable_shared_from_this { public: - typedef std::shared_ptr Ptr; - typedef unordered_map > StreamMap; - typedef unordered_map AppStreamMap; - typedef unordered_map VhostAppStreamMap; - typedef unordered_map SchemaVhostAppStreamMap; + static constexpr MediaSource *NullMediaSource = nullptr; + using Ptr = std::shared_ptr; + using StreamMap = unordered_map >; + using AppStreamMap = unordered_map; + using VhostAppStreamMap = unordered_map; + using SchemaVhostAppStreamMap = unordered_map; MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id) ; virtual ~MediaSource() ; diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index 7d707008..87543e22 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -338,7 +338,7 @@ bool MultiMediaSourceMuxer::isRecording(MediaSource &sender, Recorder::type type return _muxer->isRecording(sender,type); } -void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function &cb){ +void MultiMediaSourceMuxer::startSendRtp(MediaSource &, const string &dst_url, uint16_t dst_port, const string &ssrc, bool is_udp, uint16_t src_port, const function &cb){ #if defined(ENABLE_RTPPROXY) RtpSender::Ptr rtp_sender = std::make_shared(atoi(ssrc.data())); weak_ptr weak_self = shared_from_this(); @@ -360,12 +360,14 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const string &dst_ #endif//ENABLE_RTPPROXY } -bool MultiMediaSourceMuxer::stopSendRtp(MediaSource &sender, const string& ssrc){ +bool MultiMediaSourceMuxer::stopSendRtp(MediaSource &sender, const string &ssrc) { #if defined(ENABLE_RTPPROXY) - onceToken token(nullptr, [&]() { - //关闭rtp推流,可能触发无人观看事件 - MediaSourceEventInterceptor::onReaderChanged(sender, totalReaderCount()); - }); + if (&sender != MediaSource::NullMediaSource) { + onceToken token(nullptr, [&]() { + //关闭rtp推流,可能触发无人观看事件 + MediaSourceEventInterceptor::onReaderChanged(sender, totalReaderCount()); + }); + } if (ssrc.empty()) { //关闭全部 lock_guard lck(_rtp_sender_mtx);