From 6d16ae91e6eb43a3f1e6d16b9e76d0a59686ab46 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 30 Mar 2021 11:51:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0rtc=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ webrtc/Sdp.h | 44 ++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index d24d5a06..3b2cfc9d 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -493,6 +493,7 @@ void SdpAttrExtmap::parse(const string &str) { if (sscanf(str.data(), "%" SCNd32 " %127s", &index, buf) != 2) { SDP_THROW(); } + direction = RtpDirection::sendrecv; } else { direction = getRtpDirection(direction_buf); } @@ -1076,4 +1077,82 @@ void RtcSession::checkValid() const{ for (auto &item : media) { item.checkValid(); } +} + +void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){ + enable = true; + rtcp_mux = true; + rtcp_rsize = false; + group_bundle = true; + unified_plan = false; + support_rtx = true; + support_red = false; + support_ulpfec = false; + support_simulcast = false; + ice_lite = true; + ice_trickle = true; + ice_renomination = false; + switch (type) { + case TrackVideo: { + preferred_codec = {CodecAAC, CodecOpus, CodecG711U, CodecG711A}; + rtcp_fb = {"transport-cc"}; + extmap = {"1 urn:ietf:params:rtp-hdrext:ssrc-audio-level"}; + break; + } + case TrackAudio: { + preferred_codec = {CodecH264, CodecH265}; + rtcp_fb = {"nack", "ccm fir", "nack pli", "goog-remb", "transport-cc"}; + extmap = {"2 urn:ietf:params:rtp-hdrext:toffset", + "3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", + "4 urn:3gpp:video-orientation", + "5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01", + "6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"}; + break; + } + case TrackApplication: { + enable = false; + break; + } + default: break; + } +} + +void RtcConfigure::setDefaultSetting(string ice_ufrag, + string ice_pwd, + DtlsRole role, + RtpDirection direction, + const SdpAttrFingerprint &fingerprint) { + + video.setDefaultSetting(TrackVideo); + audio.setDefaultSetting(TrackAudio); + application.setDefaultSetting(TrackApplication); + + video.ice_ufrag = audio.ice_ufrag = application.ice_ufrag = ice_ufrag; + video.ice_pwd = audio.ice_pwd = application.ice_pwd = ice_ufrag; + video.role = audio.role = application.role = role; + video.direction = audio.direction = application.direction = direction; + video.fingerprint = audio.fingerprint = application.fingerprint = fingerprint; +} + +void RtcConfigure::addCandidate(const SdpAttrCandidate &candidate, TrackType type) { + switch (type) { + case TrackAudio: { + audio.candidate.emplace_back(candidate); + break; + } + case TrackVideo: { + video.candidate.emplace_back(candidate); + break; + } + case TrackApplication: { + application.candidate.emplace_back(candidate); + break; + } + default: { + audio.candidate.emplace_back(candidate); + video.candidate.emplace_back(candidate); + application.candidate.emplace_back(candidate); + break; + } + } } \ No newline at end of file diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index 51163e01..efca5783 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -609,5 +609,49 @@ public: void checkValid() const; }; +class RtcConfigure { +public: + class RtcTrackConfigure { + public: + bool enable; + bool rtcp_mux; + bool rtcp_rsize; + bool group_bundle; + bool unified_plan; + bool support_rtx; + bool support_red; + bool support_ulpfec; + + bool support_simulcast; + bool ice_lite; + bool ice_trickle; + bool ice_renomination; + string ice_ufrag; + string ice_pwd; + + DtlsRole role{DtlsRole::invalid}; + RtpDirection direction{RtpDirection::invalid}; + SdpAttrFingerprint fingerprint; + + vector rtcp_fb; + vector preferred_codec; + vector extmap; + vector candidate; + + void setDefaultSetting(TrackType type); + }; + + RtcTrackConfigure video; + RtcTrackConfigure audio; + RtcTrackConfigure application; + + void setDefaultSetting(string ice_ufrag, + string ice_pwd, + DtlsRole role, + RtpDirection direction, + const SdpAttrFingerprint &fingerprint); + void addCandidate(const SdpAttrCandidate &candidate, TrackType type = TrackInvalid); +}; + #endif //ZLMEDIAKIT_SDP_H