记录所有rtp的ssrc

This commit is contained in:
ziyue 2021-06-25 16:57:38 +08:00
parent a7f75774e9
commit 76ebf02ced
3 changed files with 26 additions and 5 deletions

View File

@ -624,10 +624,21 @@ void RtpExtContext::changeRtpExtId(const RtpHeader *header, bool is_recv, string
} else { } else {
//设置rid //设置rid
if (_ssrc_to_rid.emplace(ssrc, rid).second) { if (_ssrc_to_rid.emplace(ssrc, rid).second) {
InfoL << "rid of ssrc " << ssrc << " is:" << rid; onGetRtp(header->pt, ssrc, rid);
} }
} }
if (rid_ptr) { if (rid_ptr) {
*rid_ptr = rid; *rid_ptr = rid;
} }
} }
void RtpExtContext::setOnGetRtp(OnGetRtp cb) {
_cb = std::move(cb);
}
void RtpExtContext::onGetRtp(uint8_t pt, uint32_t ssrc, const string &rid){
if (_cb) {
_cb(pt, ssrc, rid);
}
}

View File

@ -112,13 +112,20 @@ class RtcMedia;
class RtpExtContext { class RtpExtContext {
public: public:
using Ptr = std::shared_ptr<RtpExtContext>; using Ptr = std::shared_ptr<RtpExtContext>;
using OnGetRtp = function<void(uint8_t pt, uint32_t ssrc, const string &rid)>;
RtpExtContext(const RtcMedia &media); RtpExtContext(const RtcMedia &media);
~RtpExtContext() = default; ~RtpExtContext() = default;
void setOnGetRtp(OnGetRtp cb);
string getRid(uint32_t ssrc) const; string getRid(uint32_t ssrc) const;
void changeRtpExtId(const RtpHeader *header, bool is_recv, string *rid_ptr = nullptr); void changeRtpExtId(const RtpHeader *header, bool is_recv, string *rid_ptr = nullptr);
private: private:
void onGetRtp(uint8_t pt, uint32_t ssrc, const string &rid);
private:
OnGetRtp _cb;
//发送rtp时需要修改rtp ext id //发送rtp时需要修改rtp ext id
map<RtpExtType, uint8_t> _rtp_ext_type_to_id; map<RtpExtType, uint8_t> _rtp_ext_type_to_id;
//接收rtp时需要修改rtp ext id //接收rtp时需要修改rtp ext id

View File

@ -412,9 +412,11 @@ void WebRtcTransportImp::onStartWebRTC() {
//send ssrc --> MediaTrack //send ssrc --> MediaTrack
_ssrc_to_track[info->answer_ssrc_rtp] = info; _ssrc_to_track[info->answer_ssrc_rtp] = info;
_ssrc_to_track[info->answer_ssrc_rtx] = info;
//recv ssrc --> MediaTrack //recv ssrc --> MediaTrack
_ssrc_to_track[info->offer_ssrc_rtp] = info; _ssrc_to_track[info->offer_ssrc_rtp] = info;
_ssrc_to_track[info->offer_ssrc_rtx] = info;
//rtp pt --> MediaTrack //rtp pt --> MediaTrack
_pt_to_track.emplace(info->plan_rtp->pt, std::make_pair(false, info)); _pt_to_track.emplace(info->plan_rtp->pt, std::make_pair(false, info));
@ -425,6 +427,11 @@ void WebRtcTransportImp::onStartWebRTC() {
if (m_offer->type != TrackApplication) { if (m_offer->type != TrackApplication) {
//记录rtp ext类型与id的关系方便接收或发送rtp时修改rtp ext id //记录rtp ext类型与id的关系方便接收或发送rtp时修改rtp ext id
info->rtp_ext_ctx = std::make_shared<RtpExtContext>(*m_offer); info->rtp_ext_ctx = std::make_shared<RtpExtContext>(*m_offer);
info->rtp_ext_ctx->setOnGetRtp([this, info](uint8_t pt, uint32_t ssrc, const string &rid) {
//ssrc --> MediaTrack
_ssrc_to_track[ssrc] = info;
InfoL << "get rtp, pt:" << (int) pt << ", ssrc:" << ssrc << ", rid:" << rid;
});
} }
} }
@ -690,8 +697,6 @@ void WebRtcTransportImp::createRtpChannel(const string &rid, uint32_t ssrc, cons
}); });
//rid --> rtp ssrc //rid --> rtp ssrc
ref->rtp_ssrc = ssrc; ref->rtp_ssrc = ssrc;
//rtp ssrc --> MediaTrack
_ssrc_to_track[ssrc] = info;
InfoL << "create rtp receiver of ssrc:" << ssrc << ", rid:" << rid << ", codec:" << info->plan_rtp->codec; InfoL << "create rtp receiver of ssrc:" << ssrc << ", rid:" << rid << ", codec:" << info->plan_rtp->codec;
} }
@ -729,7 +734,6 @@ void WebRtcTransportImp::onRtp(const char *buf, size_t len) {
auto seq = ntohs(rtp->seq); auto seq = ntohs(rtp->seq);
if (info->media->type == TrackVideo && seq % 100 == 0) { if (info->media->type == TrackVideo && seq % 100 == 0) {
//此处模拟接受丢包 //此处模拟接受丢包
DebugL << "recv dropped:" << seq << ", rid:" << rid << ", ssrc:" << ssrc;
return; return;
} }
#endif #endif
@ -820,7 +824,6 @@ void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool r
#if 0 #if 0
//此处模拟发送丢包 //此处模拟发送丢包
if (rtp->type == TrackVideo && rtp->getSeq() % 100 == 0) { if (rtp->type == TrackVideo && rtp->getSeq() % 100 == 0) {
DebugL << "send dropped:" << rtp->getSeq();
return; return;
} }
#endif #endif