添加twcc相关api

This commit is contained in:
xia-chu 2021-04-28 15:07:15 +08:00
parent ac55ae79fb
commit 9396270ce2
2 changed files with 75 additions and 44 deletions

View File

@ -921,7 +921,7 @@ void RtcSession::loadFrom(const string &str, bool check) {
} }
for (auto rtpfb_it = rtcpfb_map.find(pt); for (auto rtpfb_it = rtcpfb_map.find(pt);
rtpfb_it != rtcpfb_map.end() && rtpfb_it->second.pt == pt; ++rtpfb_it) { rtpfb_it != rtcpfb_map.end() && rtpfb_it->second.pt == pt; ++rtpfb_it) {
plan.rtcp_fb.emplace_back(rtpfb_it->second.rtcp_type); plan.rtcp_fb.emplace(rtpfb_it->second.rtcp_type);
} }
} }
} }
@ -1241,6 +1241,20 @@ const RtcMedia *RtcSession::getMedia(TrackType type) const{
return nullptr; return nullptr;
} }
static string const kTWCCRtcpFb = "transport-cc";
static string const kTWCCExtMap = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
void RtcConfigure::RtcTrackConfigure::enableTWCC(bool enable){
if (!enable) {
rtcp_fb.erase(kTWCCRtcpFb);
extmap.erase(kTWCCExtMap);
} else {
rtcp_fb.emplace(kTWCCRtcpFb);
extmap.emplace(kTWCCExtMap);
}
}
void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
enable = true; enable = true;
rtcp_mux = true; rtcp_mux = true;
@ -1256,30 +1270,34 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
case TrackAudio: { case TrackAudio: {
//此处调整偏好的编码格式优先级 //此处调整偏好的编码格式优先级
preferred_codec = {CodecAAC, CodecG711U, CodecG711A, CodecOpus}; preferred_codec = {CodecAAC, CodecG711U, CodecG711A, CodecOpus};
rtcp_fb = {"transport-cc"}; rtcp_fb = {kTWCCRtcpFb};
extmap = {"1 urn:ietf:params:rtp-hdrext:ssrc-audio-level", extmap = {
"2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", kTWCCExtMap,
"3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01", "urn:ietf:params:rtp-hdrext:ssrc-audio-level",
"4 urn:ietf:params:rtp-hdrext:sdes:mid", "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
"5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id", "urn:ietf:params:rtp-hdrext:sdes:mid",
"6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"}; "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",
"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"
};
break; break;
} }
case TrackVideo: { case TrackVideo: {
//此处调整偏好的编码格式优先级 //此处调整偏好的编码格式优先级
preferred_codec = {CodecH264, CodecH265}; preferred_codec = {CodecH264, CodecH265};
rtcp_fb = {"nack", "ccm fir", "nack pli", "goog-remb", "transport-cc"}; rtcp_fb = {kTWCCRtcpFb, "nack", "ccm fir", "nack pli", "goog-remb"};
extmap = {"14 urn:ietf:params:rtp-hdrext:toffset", extmap = {
"2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", kTWCCExtMap,
"13 urn:3gpp:video-orientation", "urn:ietf:params:rtp-hdrext:toffset",
"3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01", "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
"12 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay", "urn:3gpp:video-orientation",
"11 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type", "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay",
"7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing", "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type",
"8 http://www.webrtc.org/experiments/rtp-hdrext/color-space", "http://www.webrtc.org/experiments/rtp-hdrext/video-timing",
"4 urn:ietf:params:rtp-hdrext:sdes:mid", "http://www.webrtc.org/experiments/rtp-hdrext/color-space",
"5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id", "urn:ietf:params:rtp-hdrext:sdes:mid",
"6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"}; "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",
"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"
};
break; break;
} }
case TrackApplication: { case TrackApplication: {
@ -1333,6 +1351,29 @@ void RtcConfigure::addCandidate(const SdpAttrCandidate &candidate, TrackType typ
} }
} }
void RtcConfigure::enableTWCC(bool enable, TrackType type){
switch (type) {
case TrackAudio: {
audio.enableTWCC(enable);
break;
}
case TrackVideo: {
video.enableTWCC(enable);
break;
}
case TrackApplication: {
application.enableTWCC(enable);
break;
}
default: {
audio.enableTWCC(enable);
video.enableTWCC(enable);
application.enableTWCC(enable);
break;
}
}
}
shared_ptr<RtcSession> RtcConfigure::createAnswer(const RtcSession &offer){ shared_ptr<RtcSession> RtcConfigure::createAnswer(const RtcSession &offer){
shared_ptr<RtcSession> ret = std::make_shared<RtcSession>(); shared_ptr<RtcSession> ret = std::make_shared<RtcSession>();
ret->version = offer.version; ret->version = offer.version;
@ -1479,35 +1520,22 @@ RETRY:
} }
} }
//这是我们支持的扩展 //对方和我方都支持的扩展,那么我们才支持
unordered_set<string> extmap_set;
for (auto &ext : configure.extmap) {
SdpAttrExtmap ext_cfg;
ext_cfg.parse(ext);
extmap_set.emplace(ext_cfg.ext);
}
//对方和我方都支持的扩展,那么我们都支持
for (auto &ext : offer_media.extmap) { for (auto &ext : offer_media.extmap) {
if (extmap_set.find(ext.ext) != extmap_set.end()) { if (configure.extmap.find(ext.ext) != configure.extmap.end()) {
answer_media.extmap.emplace_back(ext); answer_media.extmap.emplace_back(ext);
} }
} }
//我们支持的rtcp类型
unordered_set<string> rtcp_fb_set; auto &rtcp_fb_ref = answer_media.plan[0].rtcp_fb;
for (auto &fp : configure.rtcp_fb) { rtcp_fb_ref.clear();
rtcp_fb_set.emplace(fp); //对方和我方都支持的rtcpfb那么我们才支持
}
vector<string> offer_rtcp_fb;
for (auto &fp : offer_plan_ptr->rtcp_fb) { for (auto &fp : offer_plan_ptr->rtcp_fb) {
if (rtcp_fb_set.find(fp) != rtcp_fb_set.end()) { if (configure.rtcp_fb.find(fp) != configure.rtcp_fb.end()) {
//对方该rtcp被我们支持 //对方该rtcp被我们支持
offer_rtcp_fb.emplace_back(fp); rtcp_fb_ref.emplace(fp);
} }
} }
//修改为我们支持的rtcp-fb类型
answer_media.plan[0].rtcp_fb.swap(offer_rtcp_fb);
ret->media.emplace_back(answer_media); ret->media.emplace_back(answer_media);
return; return;
} }

View File

@ -591,7 +591,7 @@ public:
//音频时有效 //音频时有效
uint32_t channel = 0; uint32_t channel = 0;
//rtcp反馈 //rtcp反馈
vector<string> rtcp_fb; set<string> rtcp_fb;
map<string/*key*/, string/*value*/, StrCaseCompare> fmtp; map<string/*key*/, string/*value*/, StrCaseCompare> fmtp;
string getFmtp(const char *key) const; string getFmtp(const char *key) const;
@ -693,12 +693,13 @@ public:
RtpDirection direction{RtpDirection::invalid}; RtpDirection direction{RtpDirection::invalid};
SdpAttrFingerprint fingerprint; SdpAttrFingerprint fingerprint;
vector<string> rtcp_fb; set<string> rtcp_fb;
set<string> extmap;
vector<CodecId> preferred_codec; vector<CodecId> preferred_codec;
vector<string> extmap;
vector<SdpAttrCandidate> candidate; vector<SdpAttrCandidate> candidate;
void setDefaultSetting(TrackType type); void setDefaultSetting(TrackType type);
void enableTWCC(bool enable = true);
}; };
RtcTrackConfigure video; RtcTrackConfigure video;
@ -715,6 +716,8 @@ public:
void setPlayRtspInfo(const string &sdp); void setPlayRtspInfo(const string &sdp);
void enableTWCC(bool enable = true, TrackType type = TrackInvalid);
private: private:
void matchMedia(shared_ptr<RtcSession> &ret, TrackType type, const vector<RtcMedia> &medias, const RtcTrackConfigure &configure); void matchMedia(shared_ptr<RtcSession> &ret, TrackType type, const vector<RtcMedia> &medias, const RtcTrackConfigure &configure);
bool onCheckCodecProfile(const RtcCodecPlan &plan, CodecId codec); bool onCheckCodecProfile(const RtcCodecPlan &plan, CodecId codec);