diff --git a/webrtc/RtpExt.cpp b/webrtc/RtpExt.cpp index 99581ca7..dfbf10a0 100644 --- a/webrtc/RtpExt.cpp +++ b/webrtc/RtpExt.cpp @@ -624,10 +624,21 @@ void RtpExtContext::changeRtpExtId(const RtpHeader *header, bool is_recv, string } else { //设置rid if (_ssrc_to_rid.emplace(ssrc, rid).second) { - InfoL << "rid of ssrc " << ssrc << " is:" << rid; + onGetRtp(header->pt, ssrc, rid); } } if (rid_ptr) { *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); + } +} + diff --git a/webrtc/RtpExt.h b/webrtc/RtpExt.h index 71774657..d7a90386 100644 --- a/webrtc/RtpExt.h +++ b/webrtc/RtpExt.h @@ -112,13 +112,20 @@ class RtcMedia; class RtpExtContext { public: using Ptr = std::shared_ptr; + using OnGetRtp = function; + RtpExtContext(const RtcMedia &media); ~RtpExtContext() = default; + void setOnGetRtp(OnGetRtp cb); string getRid(uint32_t ssrc) const; void changeRtpExtId(const RtpHeader *header, bool is_recv, string *rid_ptr = nullptr); private: + void onGetRtp(uint8_t pt, uint32_t ssrc, const string &rid); + +private: + OnGetRtp _cb; //发送rtp时需要修改rtp ext id map _rtp_ext_type_to_id; //接收rtp时需要修改rtp ext id diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index b2f095d1..5c76633a 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -412,9 +412,11 @@ void WebRtcTransportImp::onStartWebRTC() { //send ssrc --> MediaTrack _ssrc_to_track[info->answer_ssrc_rtp] = info; + _ssrc_to_track[info->answer_ssrc_rtx] = info; //recv ssrc --> MediaTrack _ssrc_to_track[info->offer_ssrc_rtp] = info; + _ssrc_to_track[info->offer_ssrc_rtx] = info; //rtp pt --> MediaTrack _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) { //记录rtp ext类型与id的关系,方便接收或发送rtp时修改rtp ext id info->rtp_ext_ctx = std::make_shared(*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 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; } @@ -729,7 +734,6 @@ void WebRtcTransportImp::onRtp(const char *buf, size_t len) { auto seq = ntohs(rtp->seq); if (info->media->type == TrackVideo && seq % 100 == 0) { //此处模拟接受丢包 - DebugL << "recv dropped:" << seq << ", rid:" << rid << ", ssrc:" << ssrc; return; } #endif @@ -820,7 +824,6 @@ void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool r #if 0 //此处模拟发送丢包 if (rtp->type == TrackVideo && rtp->getSeq() % 100 == 0) { - DebugL << "send dropped:" << rtp->getSeq(); return; } #endif