startSendRtp接口新增支持同ssrc向多个服务器推流 (#2951)

新增ssrc_multi_send参数,支持同ssrc向多个服务器推流,兼容当前startSendRtp/stopSendRtp接口
This commit is contained in:
Dw9 2023-11-07 23:38:58 +08:00 committed by GitHub
parent 1609fe67d7
commit f8285a3f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 4 deletions

View File

@ -1710,10 +1710,16 @@
"value": "obs", "value": "obs",
"description": "流id例如 obs" "description": "流id例如 obs"
}, },
{
"key": "ssrc_multi_send",
"value": "0",
"description": "是否支持同ssrc推流到多个上级服务器,该参数非必选参数 默认false",
"disabled": true
},
{ {
"key": "ssrc", "key": "ssrc",
"value": "1", "value": "1",
"description": "rtp推流的ssrcssrc不同时可以推流到多个上级服务器" "description": "rtp推流的ssrc"
}, },
{ {
"key": "dst_url", "key": "dst_url",

View File

@ -1245,6 +1245,7 @@ void installWebApi() {
args.passive = false; args.passive = false;
args.dst_url = allArgs["dst_url"]; args.dst_url = allArgs["dst_url"];
args.dst_port = allArgs["dst_port"]; args.dst_port = allArgs["dst_port"];
args.ssrc_multi_send = allArgs["ssrc_multi_send"].empty() ? false : allArgs["ssrc_multi_send"].as<bool>();
args.ssrc = allArgs["ssrc"]; args.ssrc = allArgs["ssrc"];
args.is_udp = allArgs["is_udp"]; args.is_udp = allArgs["is_udp"];
args.src_port = allArgs["src_port"]; args.src_port = allArgs["src_port"];

View File

@ -104,6 +104,8 @@ public:
bool passive = false; bool passive = false;
// rtp payload type // rtp payload type
uint8_t pt = 96; uint8_t pt = 96;
//是否支持同ssrc多服务器发送
bool ssrc_multi_send = false;
// 指定rtp ssrc // 指定rtp ssrc
std::string ssrc; std::string ssrc;
// 指定本地发送端口 // 指定本地发送端口

View File

@ -291,12 +291,14 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const MediaSourceE
auto ring = _ring; auto ring = _ring;
auto ssrc = args.ssrc; auto ssrc = args.ssrc;
auto ssrc_multi_send = args.ssrc_multi_send;
auto tracks = getTracks(false); auto tracks = getTracks(false);
auto poller = getOwnerPoller(sender); auto poller = getOwnerPoller(sender);
auto rtp_sender = std::make_shared<RtpSender>(poller); auto rtp_sender = std::make_shared<RtpSender>(poller);
weak_ptr<MultiMediaSourceMuxer> weak_self = shared_from_this(); weak_ptr<MultiMediaSourceMuxer> weak_self = shared_from_this();
rtp_sender->startSend(args, [ssrc, weak_self, rtp_sender, cb, tracks, ring, poller](uint16_t local_port, const SockException &ex) mutable { rtp_sender->startSend(args, [ssrc,ssrc_multi_send, weak_self, rtp_sender, cb, tracks, ring, poller](uint16_t local_port, const SockException &ex) mutable {
cb(local_port, ex); cb(local_port, ex);
auto strong_self = weak_self.lock(); auto strong_self = weak_self.lock();
if (!strong_self || ex) { if (!strong_self || ex) {
@ -325,7 +327,10 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const MediaSourceE
// 可能归属线程发生变更 // 可能归属线程发生变更
strong_self->getOwnerPoller(MediaSource::NullMediaSource())->async([=]() { strong_self->getOwnerPoller(MediaSource::NullMediaSource())->async([=]() {
strong_self->_rtp_sender[ssrc] = std::move(reader); if(!ssrc_multi_send) {
strong_self->_rtp_sender.erase(ssrc);
}
strong_self->_rtp_sender.emplace(ssrc,reader);
}); });
}); });
#else #else

View File

@ -168,7 +168,7 @@ private:
toolkit::Ticker _last_check; toolkit::Ticker _last_check;
Stamp _stamp[2]; Stamp _stamp[2];
std::weak_ptr<Listener> _track_listener; std::weak_ptr<Listener> _track_listener;
std::unordered_map<std::string, RingType::RingReader::Ptr> _rtp_sender; std::unordered_multimap<std::string, RingType::RingReader::Ptr> _rtp_sender;
FMP4MediaSourceMuxer::Ptr _fmp4; FMP4MediaSourceMuxer::Ptr _fmp4;
RtmpMediaSourceMuxer::Ptr _rtmp; RtmpMediaSourceMuxer::Ptr _rtmp;
RtspMediaSourceMuxer::Ptr _rtsp; RtspMediaSourceMuxer::Ptr _rtsp;