From f4ee607febd032b3b5c1146b0a3bc799a99213d0 Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 11 May 2023 20:47:40 +0800 Subject: [PATCH] add RtspMediaSource::Clone --- src/Rtsp/RtspMediaSource.h | 4 ++++ src/Rtsp/RtspMediaSourceImp.cpp | 6 ++++++ src/Rtsp/RtspMediaSourceImp.h | 1 + webrtc/WebRtcPusher.cpp | 9 ++++----- webrtc/WebRtcPusher.h | 8 ++++---- webrtc/WebRtcTransport.cpp | 2 ++ 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Rtsp/RtspMediaSource.h b/src/Rtsp/RtspMediaSource.h index 4296f131..b6dc3d46 100644 --- a/src/Rtsp/RtspMediaSource.h +++ b/src/Rtsp/RtspMediaSource.h @@ -76,6 +76,10 @@ public: return _sdp; } + virtual RtspMediaSource::Ptr Clone(const std::string& stream) { + return nullptr; + } + /** * 获取相应轨道的ssrc */ diff --git a/src/Rtsp/RtspMediaSourceImp.cpp b/src/Rtsp/RtspMediaSourceImp.cpp index 7354306f..b10b071c 100644 --- a/src/Rtsp/RtspMediaSourceImp.cpp +++ b/src/Rtsp/RtspMediaSourceImp.cpp @@ -126,6 +126,12 @@ void RtspMediaSourceImp::setProtocolOption(const ProtocolOption &option) } } +RtspMediaSource::Ptr RtspMediaSourceImp::Clone(const std::string &stream) { + auto src_imp = std::make_shared(getVhost(), getApp(), stream); + src_imp->setSdp(getSdp()); + src_imp->setProtocolOption(getProtocolOption()); + return src_imp; +} } diff --git a/src/Rtsp/RtspMediaSourceImp.h b/src/Rtsp/RtspMediaSourceImp.h index 385fc80a..ca341836 100644 --- a/src/Rtsp/RtspMediaSourceImp.h +++ b/src/Rtsp/RtspMediaSourceImp.h @@ -107,6 +107,7 @@ public: } } + RtspMediaSource::Ptr Clone(const std::string& stream) override; private: bool _all_track_ready = false; ProtocolOption _option; diff --git a/webrtc/WebRtcPusher.cpp b/webrtc/WebRtcPusher.cpp index 8fe6549c..03e25200 100644 --- a/webrtc/WebRtcPusher.cpp +++ b/webrtc/WebRtcPusher.cpp @@ -10,13 +10,14 @@ #include "WebRtcPusher.h" #include "Common/config.h" +#include "Rtsp/RtspMediaSourceImp.h" using namespace std; namespace mediakit { WebRtcPusher::Ptr WebRtcPusher::create(const EventPoller::Ptr &poller, - const RtspMediaSourceImp::Ptr &src, + const RtspMediaSource::Ptr &src, const std::shared_ptr &ownership, const MediaInfo &info, const ProtocolOption &option, @@ -30,7 +31,7 @@ WebRtcPusher::Ptr WebRtcPusher::create(const EventPoller::Ptr &poller, } WebRtcPusher::WebRtcPusher(const EventPoller::Ptr &poller, - const RtspMediaSourceImp::Ptr &src, + const RtspMediaSource::Ptr &src, const std::shared_ptr &ownership, const MediaInfo &info, const ProtocolOption &option, @@ -98,10 +99,8 @@ void WebRtcPusher::onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Pt auto &src = _push_src_sim[rid]; if (!src) { auto stream_id = rid.empty() ? _push_src->getId() : _push_src->getId() + "_" + rid; - auto src_imp = std::make_shared(_push_src->getVhost(), _push_src->getApp(), stream_id); + auto src_imp = _push_src->Clone(stream_id); _push_src_sim_ownership[rid] = src_imp->getOwnership(); - src_imp->setSdp(_push_src->getSdp()); - src_imp->setProtocolOption(_push_src->getProtocolOption()); src_imp->setListener(static_pointer_cast(shared_from_this())); src = src_imp; } diff --git a/webrtc/WebRtcPusher.h b/webrtc/WebRtcPusher.h index f00e0483..32c47055 100644 --- a/webrtc/WebRtcPusher.h +++ b/webrtc/WebRtcPusher.h @@ -12,7 +12,7 @@ #define ZLMEDIAKIT_WEBRTCPUSHER_H #include "WebRtcTransport.h" -#include "Rtsp/RtspMediaSourceImp.h" +#include "Rtsp/RtspMediaSource.h" namespace mediakit { @@ -20,7 +20,7 @@ class WebRtcPusher : public WebRtcTransportImp, public MediaSourceEvent { public: using Ptr = std::shared_ptr; ~WebRtcPusher() override = default; - static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSourceImp::Ptr &src, + static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const std::shared_ptr &ownership, const MediaInfo &info, const ProtocolOption &option, bool preferred_tcp = false); protected: @@ -51,7 +51,7 @@ protected: float getLossRate(MediaSource &sender,TrackType type) override; private: - WebRtcPusher(const EventPoller::Ptr &poller, const RtspMediaSourceImp::Ptr &src, + WebRtcPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const std::shared_ptr &ownership, const MediaInfo &info, const ProtocolOption &option, bool preferred_tcp); private: @@ -61,7 +61,7 @@ private: //媒体相关元数据 MediaInfo _media_info; //推流的rtsp源 - RtspMediaSourceImp::Ptr _push_src; + RtspMediaSource::Ptr _push_src; //推流所有权 std::shared_ptr _push_src_ownership; //推流的rtsp源,支持simulcast diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index fe8c6e5c..1c9fb0fc 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -23,6 +23,8 @@ #include "WebRtcPlayer.h" #include "WebRtcPusher.h" +#include "Rtsp/RtspMediaSourceImp.h" + #define RTP_SSRC_OFFSET 1 #define RTX_SSRC_OFFSET 2 #define RTP_CNAME "zlmediakit-rtp"