diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 86930d6d..048b5609 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -40,6 +40,17 @@ string getOriginTypeString(MediaOriginType type){ } } +static string getOriginUrl_l(const MediaSource *thiz) { + if (thiz == MediaSource::NullMediaSource) { + return ""; + } + return thiz->getSchema() + "://" + thiz->getVhost() + "/" + thiz->getApp() + "/" + thiz->getId(); +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +MediaSource * const MediaSource::NullMediaSource = nullptr; + MediaSource::MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id){ GET_CONFIG(bool, enableVhost, General::kEnableVhost); if (!enableVhost) { @@ -136,9 +147,13 @@ MediaOriginType MediaSource::getOriginType() const { string MediaSource::getOriginUrl() const { auto listener = _listener.lock(); if (!listener) { - return ""; + return getOriginUrl_l(this); } - return listener->getOriginUrl(const_cast(*this)); + auto ret = listener->getOriginUrl(const_cast(*this)); + if (!ret.empty()) { + return ret; + } + return getOriginUrl_l(this); } std::shared_ptr MediaSource::getOriginSock() const { @@ -567,6 +582,10 @@ void MediaSourceEvent::onReaderChanged(MediaSource &sender, int size){ }, nullptr); } +string MediaSourceEvent::getOriginUrl(MediaSource &sender) const { + return getOriginUrl_l(&sender); +} + MediaOriginType MediaSourceEventInterceptor::getOriginType(MediaSource &sender) const { auto listener = _listener.lock(); if (!listener) { @@ -578,9 +597,13 @@ MediaOriginType MediaSourceEventInterceptor::getOriginType(MediaSource &sender) string MediaSourceEventInterceptor::getOriginUrl(MediaSource &sender) const { auto listener = _listener.lock(); if (!listener) { - return ""; + return MediaSourceEvent::getOriginUrl(sender); } - return listener->getOriginUrl(sender); + auto ret = listener->getOriginUrl(sender); + if (!ret.empty()) { + return ret; + } + return MediaSourceEvent::getOriginUrl(sender); } std::shared_ptr MediaSourceEventInterceptor::getOriginSock(MediaSource &sender) const { diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index d99dfbbb..d77fbe25 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -61,7 +61,7 @@ public: // 获取媒体源类型 virtual MediaOriginType getOriginType(MediaSource &sender) const { return MediaOriginType::unknown; } // 获取媒体源url或者文件路径 - virtual string getOriginUrl(MediaSource &sender) const { return ""; } + virtual string getOriginUrl(MediaSource &sender) const; // 获取媒体源客户端相关信息 virtual std::shared_ptr getOriginSock(MediaSource &sender) const { return nullptr; } @@ -198,7 +198,7 @@ private: */ class MediaSource: public TrackSource, public enable_shared_from_this { public: - static constexpr MediaSource *NullMediaSource = nullptr; + static MediaSource * const NullMediaSource; using Ptr = std::shared_ptr; using StreamMap = unordered_map >; using AppStreamMap = unordered_map; diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index 30fcdfa1..a06999b9 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -58,6 +58,14 @@ static string getTrackInfoStr(const TrackSource *track_src){ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec, bool enable_rtsp, bool enable_rtmp, bool enable_hls, bool enable_mp4) { + _get_origin_url = [this, vhost, app, stream]() { + auto ret = getOriginUrl(*MediaSource::NullMediaSource); + if (!ret.empty()) { + return ret; + } + return vhost + "/" + app + "/" + stream; + }; + if (enable_rtmp) { _rtmp = std::make_shared(vhost, app, stream, std::make_shared(dur_sec)); } @@ -286,7 +294,7 @@ void MultiMediaSourceMuxer::onAllTrackReady() { if (listener) { listener->onAllTrackReady(); } - InfoL << "stream: " << getOriginUrl(*MediaSource::NullMediaSource) << " , codec info: " << getTrackInfoStr(this); + InfoL << "stream: " << _get_origin_url() << " , codec info: " << getTrackInfoStr(this); } void MultiMediaSourceMuxer::resetTracks() { diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index 5defdbff..5ae15e95 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -145,6 +145,7 @@ private: Ticker _last_check; Stamp _stamp[2]; std::weak_ptr _track_listener; + function _get_origin_url; #if defined(ENABLE_RTPPROXY) mutex _rtp_sender_mtx; unordered_map _rtp_sender; diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 6a18437a..79042d73 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -262,10 +262,10 @@ MediaOriginType RtpProcess::getOriginType(MediaSource &sender) const{ } string RtpProcess::getOriginUrl(MediaSource &sender) const { - return _media_info._full_url; + return _media_info._schema + "://" + _media_info._vhost + "/" + _media_info._app + "/" + _media_info._streamid; } -std::shared_ptr RtpProcess::getOriginSock(MediaSource &sender) const{ +std::shared_ptr RtpProcess::getOriginSock(MediaSource &sender) const { return const_cast(this)->shared_from_this(); }