From a1b2aa9abb3cdf9445e82f58e9b9b406d46c509d Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 29 Mar 2021 23:55:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=B8=8E=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-- webrtc/Sdp.h | 43 +++++++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 0cfa1892..10074f7d 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -949,9 +949,7 @@ void RtcSession::loadFrom(const string &str) { if (group.isFID()) { ssrc_rtp = group.u.fid.rtp_ssrc; ssrc_rtx = group.u.fid.rtx_ssrc; - rtc_media.rtx = true; } else if (group.isSIM()) { - rtc_media.simulcast = true; ssrc_rtp_low = group.u.sim.rtp_ssrc_low; ssrc_rtp_mid = group.u.sim.rtp_ssrc_mid; ssrc_rtp_high = group.u.sim.rtp_ssrc_high; @@ -1033,4 +1031,55 @@ void RtcSession::loadFrom(const string &str) { } group = sdp.getItemClass('a', "group"); + checkValid(); } + +string RtcCodecPlan::getFmtp(const char *key) const{ + for (auto &item : fmtp) { + if (item.first == key) { + return item.second; + } + } + return ""; +} + +const RtcCodecPlan *RtcMedia::getPlan(uint8_t pt) const{ + for (auto &item : plan) { + if (item.pt == pt) { + return &item; + } + } + return nullptr; +} + +void RtcMedia::checkValid() const{ + switch (direction) { + case RtpDirection::sendonly: + case RtpDirection::sendrecv: { + if (rtp_ssrc.empty()) { + throw std::invalid_argument("发送rtp但是未指定rtp ssrc"); + } + break; + } + default: break; + } + for (auto &item : plan) { + if (item.codec == "rtx") { + if (rtx_ssrc.empty()) { + throw std::invalid_argument("指定开启rtx但是未指定rtx ssrc"); + } + auto apt = atoi(item.getFmtp("apt").data()); + if (!getPlan(apt)) { + throw std::invalid_argument("找不到rtx关联的plan信息"); + } + } + } + //todo 校验更多信息 +} + +void RtcSession::checkValid() const{ + for (auto &item : media) { + item.checkValid(); + } + //todo 校验更多信息 +} \ No newline at end of file diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index ed2ddad5..60f8c6b8 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -517,6 +517,8 @@ public: string msid; string mslabel; string label; + + bool empty() const {return ssrc == 0;} }; //rtc传输编码方案 @@ -527,47 +529,48 @@ public: uint32_t sample_rate; //音频时有效 uint32_t channel = 0; + //rtcp反馈 vector rtcp_fb; vector > fmtp; + + string getFmtp(const char *key) const; }; //rtc 媒体描述 class RtcMedia{ public: - TrackType type; + TrackType type{TrackType::TrackInvalid}; string mid; - uint16_t port; + uint16_t port{0}; + SdpConnection addr; string proto; + RtpDirection direction{RtpDirection::invalid}; + vector plan; //////// rtp //////// RtcSSRC rtp_ssrc; - // for simulcast - bool simulcast{false}; + RtcSSRC rtx_ssrc; + + //////// simulcast //////// RtcSSRC rtp_ssrc_low; RtcSSRC rtp_ssrc_mid; RtcSSRC rtp_ssrc_high; - SdpConnection addr; - RtpDirection direction; - vector plan; - - //////// rtx - rtcp //////// - bool rtx{false}; - bool rtcp_mux; - bool rtcp_rsize; - RtcSSRC rtx_ssrc; + //////// rtcp //////// + bool rtcp_mux{false}; + bool rtcp_rsize{false}; SdpAttrRtcp rtcp_addr; //////// ice //////// - bool ice_trickle; - bool ice_lite; - bool ice_renomination; + bool ice_trickle{false}; + bool ice_lite{false}; + bool ice_renomination{false}; string ice_ufrag; string ice_pwd; std::vector candidate; //////// dtls //////// - DtlsRole role; + DtlsRole role{DtlsRole::invalid}; SdpAttrFingerprint fingerprint; //////// extmap //////// @@ -575,7 +578,10 @@ public: //////// sctp //////////// SdpAttrSctpMap sctpmap; - uint32_t sctp_port {0}; + uint32_t sctp_port{0}; + + void checkValid() const; + const RtcCodecPlan *getPlan(uint8_t pt) const; }; class RtcSession{ @@ -591,6 +597,7 @@ public: SdpAttrGroup group; void loadFrom(const string &sdp); + void checkValid() const; };