From 208b0865bd18c9d68787dae84acea2501578c4ed Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 23 Aug 2022 14:11:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=A8=E5=B1=80=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=BA=E5=BA=8F=E9=94=99?= =?UTF-8?q?=E4=B9=B1=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/source/mk_media.cpp | 4 ++-- src/Common/MediaSource.cpp | 6 ++++-- src/Common/MediaSource.h | 2 +- src/Common/MultiMediaSourceMuxer.cpp | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/api/source/mk_media.cpp b/api/source/mk_media.cpp index b029fb3e..747f57cf 100755 --- a/api/source/mk_media.cpp +++ b/api/source/mk_media.cpp @@ -266,7 +266,7 @@ API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_u args.is_udp = is_udp; //sender参数无用 - (*obj)->getChannel()->startSendRtp(MediaSource::NullMediaSource, args, [cb, user_data](uint16_t local_port, const SockException &ex){ + (*obj)->getChannel()->startSendRtp(MediaSource::NullMediaSource(), args, [cb, user_data](uint16_t local_port, const SockException &ex){ if (cb) { cb(user_data, local_port, ex.getErrCode(), ex.what()); } @@ -277,5 +277,5 @@ API_EXPORT int API_CALL mk_media_stop_send_rtp(mk_media ctx, const char *ssrc){ assert(ctx); MediaHelper::Ptr *obj = (MediaHelper::Ptr *) ctx; //sender参数无用 - return (*obj)->getChannel()->stopSendRtp(MediaSource::NullMediaSource, ssrc ? ssrc : ""); + return (*obj)->getChannel()->stopSendRtp(MediaSource::NullMediaSource(), ssrc ? ssrc : ""); } \ No newline at end of file diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 8a27ba10..c89d5fc5 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -53,8 +53,10 @@ struct MediaSourceNull : public MediaSource { int readerCount() override { return 0; } }; -static std::shared_ptr s_null = std::make_shared(); -MediaSource &MediaSource::NullMediaSource = *s_null; +MediaSource &MediaSource::NullMediaSource() { + static std::shared_ptr s_null = std::make_shared(); + return *s_null; +} MediaSource::MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id){ GET_CONFIG(bool, enableVhost, General::kEnableVhost); diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 1ca816b8..bdf6c58f 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -235,7 +235,7 @@ private: */ class MediaSource: public TrackSource, public std::enable_shared_from_this { public: - static MediaSource& NullMediaSource; + static MediaSource& NullMediaSource(); using Ptr = std::shared_ptr; using StreamMap = std::unordered_map >; using AppStreamMap = std::unordered_map; diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index b76538df..9528dcad 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -78,7 +78,7 @@ static string getTrackInfoStr(const TrackSource *track_src){ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec, const ProtocolOption &option) { _option = option; _get_origin_url = [this, vhost, app, stream]() { - auto ret = getOriginUrl(MediaSource::NullMediaSource); + auto ret = getOriginUrl(MediaSource::NullMediaSource()); if (!ret.empty()) { return ret; } @@ -240,11 +240,11 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &, const MediaSourceEvent:: WarnL << "stream:" << strong_self->_get_origin_url() << " stop send rtp:" << ssrc; strong_self->_rtp_sender.erase(ssrc); //触发观看人数统计 - strong_self->onReaderChanged(MediaSource::NullMediaSource, strong_self->totalReaderCount()); + strong_self->onReaderChanged(MediaSource::NullMediaSource(), strong_self->totalReaderCount()); } }); strong_self->_rtp_sender[args.ssrc] = std::move(rtp_sender); - strong_self->onReaderChanged(MediaSource::NullMediaSource, strong_self->totalReaderCount()); + strong_self->onReaderChanged(MediaSource::NullMediaSource(), strong_self->totalReaderCount()); }); #else cb(0, SockException(Err_other, "该功能未启用,编译时请打开ENABLE_RTPPROXY宏"));