openrtpserver接口新增ssrc参数,强制过滤不属于本端口的视频流,以解决视频串流问题 (#1572)

This commit is contained in:
wangcker
2022-04-16 15:12:49 +08:00
committed by GitHub
parent 2b460c97ed
commit e712639e33
6 changed files with 34 additions and 10 deletions

View File

@@ -21,10 +21,12 @@ namespace mediakit{
const string RtpSession::kStreamID = "stream_id";
const string RtpSession::kIsUDP = "is_udp";
const string RtpSession::kSSRC = "ssrc";
void RtpSession::attachServer(const Server &server) {
_stream_id = const_cast<Server &>(server)[kStreamID];
_is_udp = const_cast<Server &>(server)[kIsUDP];
_ssrc = const_cast<Server &>(server)[kSSRC];
if (_is_udp) {
//设置udp socket读缓存
@@ -89,7 +91,8 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
}
}
if (!_process) {
if (!RtpSelector::getSSRC(data, len, _ssrc)) {
//未设置ssrc时尝试获取ssrc
if (!_ssrc && !RtpSelector::getSSRC(data, len, _ssrc)) {
return;
}
if (_stream_id.empty()) {
@@ -101,6 +104,12 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
_process->setListener(dynamic_pointer_cast<RtpSession>(shared_from_this()));
}
try {
uint32_t rtp_ssrc = 0;
RtpSelector::getSSRC(data, len, rtp_ssrc);
if (rtp_ssrc != _ssrc) {
WarnP(this) << "ssrc不匹配,rtp已丢弃:" << rtp_ssrc << " != " << _ssrc;
return;
}
_process->inputRtp(false, getSock(), data, len, &_addr);
} catch (RtpTrack::BadRtpException &ex) {
if (!_is_udp) {