Format code

This commit is contained in:
xiongziliang 2024-03-23 23:08:10 +08:00
parent d8893877b2
commit 7aaafa18e7
2 changed files with 436 additions and 460 deletions

View File

@ -26,7 +26,7 @@ static onceToken token([]() {
mINI::Instance()[kPreferredCodecA] = "PCMA,PCMU,opus,mpeg4-generic"; mINI::Instance()[kPreferredCodecA] = "PCMA,PCMU,opus,mpeg4-generic";
mINI::Instance()[kPreferredCodecV] = "H264,H265,AV1,VP9,VP8"; mINI::Instance()[kPreferredCodecV] = "H264,H265,AV1,VP9,VP8";
}); });
} } // namespace Rtc
using onCreateSdpItem = function<SdpItem::Ptr(const string &key, const string &value)>; using onCreateSdpItem = function<SdpItem::Ptr(const string &key, const string &value)>;
static map<string, onCreateSdpItem, StrCaseCompare> sdpItemCreator; static map<string, onCreateSdpItem, StrCaseCompare> sdpItemCreator;
@ -73,9 +73,7 @@ public:
class DirectionInterfaceImp : public SdpItem, public DirectionInterface { class DirectionInterfaceImp : public SdpItem, public DirectionInterface {
public: public:
DirectionInterfaceImp(RtpDirection direct){ DirectionInterfaceImp(RtpDirection direct) { direction = direct; }
direction = direct;
}
const char *getKey() const override { return getRtpDirectionString(getDirection()); } const char *getKey() const override { return getRtpDirectionString(getDirection()); }
RtpDirection getDirection() const override { return direction; } RtpDirection getDirection() const override { return direction; }
@ -717,8 +715,7 @@ void SdpAttrCandidate::parse(const string &str) {
string SdpAttrCandidate::toString() const { string SdpAttrCandidate::toString() const {
if (value.empty()) { if (value.empty()) {
value = foundation + " " + to_string(component) + " " + transport + " " + to_string(priority) + value = foundation + " " + to_string(component) + " " + transport + " " + to_string(priority) + " " + address + " " + to_string(port) + " typ " + type;
" " + address + " " + to_string(port) + " typ " + type;
for (auto &pr : arr) { for (auto &pr : arr) {
value += ' '; value += ' ';
value += pr.first; value += pr.first;
@ -952,8 +949,7 @@ void RtcSession::loadFrom(const string &str) {
if (fmtp_it != fmtp_map.end()) { if (fmtp_it != fmtp_map.end()) {
plan.fmtp = fmtp_it->second.fmtp; plan.fmtp = fmtp_it->second.fmtp;
} }
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(rtpfb_it->second.rtcp_type); plan.rtcp_fb.emplace(rtpfb_it->second.rtcp_type);
} }
} }
@ -986,8 +982,7 @@ void RtcSdpBase::toRtsp() {
case 'a': { case 'a': {
auto attr = dynamic_pointer_cast<SdpAttr>(*it); auto attr = dynamic_pointer_cast<SdpAttr>(*it);
CHECK(attr); CHECK(attr);
if (!strcasecmp(attr->detail->getKey(), "rtpmap") if (!strcasecmp(attr->detail->getKey(), "rtpmap") || !strcasecmp(attr->detail->getKey(), "fmtp")) {
|| !strcasecmp(attr->detail->getKey(), "fmtp")) {
++it; ++it;
break; break;
} }
@ -1221,9 +1216,9 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{
} }
} }
} }
if(ice_lite) if (ice_lite) {
sdp.addAttr(std::make_shared<SdpCommon>("ice-lite")); sdp.addAttr(std::make_shared<SdpCommon>("ice-lite"));
}
return ret; return ret;
} }
@ -1427,16 +1422,14 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
preferred_codec = s_preferred_codec; preferred_codec = s_preferred_codec;
rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb }; rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb };
extmap = { extmap = { { RtpExtType::ssrc_audio_level, RtpDirection::sendrecv },
{RtpExtType::ssrc_audio_level, RtpDirection::sendrecv},
{ RtpExtType::csrc_audio_level, RtpDirection::sendrecv }, { RtpExtType::csrc_audio_level, RtpDirection::sendrecv },
{ RtpExtType::abs_send_time, RtpDirection::sendrecv }, { RtpExtType::abs_send_time, RtpDirection::sendrecv },
{ RtpExtType::transport_cc, RtpDirection::sendrecv }, { RtpExtType::transport_cc, RtpDirection::sendrecv },
// rtx重传rtp时忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时如果存在sdes_mid的ext,将导致无法播放 // rtx重传rtp时忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时如果存在sdes_mid的ext,将导致无法播放
//{RtpExtType::sdes_mid,RtpDirection::sendrecv}, //{RtpExtType::sdes_mid,RtpDirection::sendrecv},
{ RtpExtType::sdes_rtp_stream_id, RtpDirection::sendrecv }, { RtpExtType::sdes_rtp_stream_id, RtpDirection::sendrecv },
{RtpExtType::sdes_repaired_rtp_stream_id, RtpDirection::sendrecv} { RtpExtType::sdes_repaired_rtp_stream_id, RtpDirection::sendrecv } };
};
break; break;
} }
case TrackVideo: { case TrackVideo: {
@ -1446,8 +1439,7 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
preferred_codec = s_preferred_codec; preferred_codec = s_preferred_codec;
rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb, "nack", "ccm fir", "nack pli" }; rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb, "nack", "ccm fir", "nack pli" };
extmap = { extmap = { { RtpExtType::abs_send_time, RtpDirection::sendrecv },
{RtpExtType::abs_send_time, RtpDirection::sendrecv},
{ RtpExtType::transport_cc, RtpDirection::sendrecv }, { RtpExtType::transport_cc, RtpDirection::sendrecv },
// rtx重传rtp时忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时如果存在sdes_mid的ext,将导致无法播放 // rtx重传rtp时忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时如果存在sdes_mid的ext,将导致无法播放
//{RtpExtType::sdes_mid,RtpDirection::sendrecv}, //{RtpExtType::sdes_mid,RtpDirection::sendrecv},
@ -1460,8 +1452,7 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
// 手机端推webrtc 会带有旋转角度rtc协议能正常播放 其他协议拉流画面旋转 // 手机端推webrtc 会带有旋转角度rtc协议能正常播放 其他协议拉流画面旋转
//{RtpExtType::video_orientation, RtpDirection::sendrecv}, //{RtpExtType::video_orientation, RtpDirection::sendrecv},
{ RtpExtType::toffset, RtpDirection::sendrecv }, { RtpExtType::toffset, RtpDirection::sendrecv },
{RtpExtType::framemarking, RtpDirection::sendrecv} { RtpExtType::framemarking, RtpDirection::sendrecv } };
};
break; break;
} }
case TrackApplication: { case TrackApplication: {
@ -1471,8 +1462,7 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
} }
} }
void RtcConfigure::setDefaultSetting(string ice_ufrag, string ice_pwd, RtpDirection direction, void RtcConfigure::setDefaultSetting(string ice_ufrag, string ice_pwd, RtpDirection direction, const SdpAttrFingerprint &fingerprint) {
const SdpAttrFingerprint &fingerprint) {
video.setDefaultSetting(TrackVideo); video.setDefaultSetting(TrackVideo);
audio.setDefaultSetting(TrackAudio); audio.setDefaultSetting(TrackAudio);
application.setDefaultSetting(TrackApplication); application.setDefaultSetting(TrackApplication);
@ -1683,8 +1673,7 @@ RETRY:
answer_media.role = mathDtlsRole(offer_media.role); answer_media.role = mathDtlsRole(offer_media.role);
// 如果codec匹配失败那么禁用该track // 如果codec匹配失败那么禁用该track
answer_media.direction = check_codec ? matchDirection(offer_media.direction, configure.direction) answer_media.direction = check_codec ? matchDirection(offer_media.direction, configure.direction) : RtpDirection::inactive;
: RtpDirection::inactive;
if (answer_media.direction == RtpDirection::invalid) { if (answer_media.direction == RtpDirection::invalid) {
continue; continue;
} }

View File

@ -77,11 +77,7 @@ enum class DtlsRole {
actpass, actpass,
}; };
enum class SdpType { enum class SdpType { invalid = -1, offer, answer };
invalid = -1,
offer,
answer
};
DtlsRole getDtlsRole(const std::string &str); DtlsRole getDtlsRole(const std::string &str);
const char *getDtlsRoleString(DtlsRole role); const char *getDtlsRoleString(DtlsRole role);
@ -92,17 +88,11 @@ class SdpItem {
public: public:
using Ptr = std::shared_ptr<SdpItem>; using Ptr = std::shared_ptr<SdpItem>;
virtual ~SdpItem() = default; virtual ~SdpItem() = default;
virtual void parse(const std::string &str) { virtual void parse(const std::string &str) { value = str; }
value = str; virtual std::string toString() const { return value; }
}
virtual std::string toString() const {
return value;
}
virtual const char *getKey() const = 0; virtual const char *getKey() const = 0;
void reset() { void reset() { value.clear(); }
value.clear();
}
protected: protected:
mutable std::string value; mutable std::string value;
@ -259,9 +249,7 @@ public:
void parse(const std::string &str) override; void parse(const std::string &str) override;
std::string toString() const override; std::string toString() const override;
const char *getKey() const override { return "msid-semantic"; } const char *getKey() const override { return "msid-semantic"; }
bool empty() const { bool empty() const { return msid.empty(); }
return msid.empty();
}
}; };
class SdpAttrRtcp : public SdpItem { class SdpAttrRtcp : public SdpItem {
@ -271,12 +259,11 @@ public:
std::string nettype { "IN" }; std::string nettype { "IN" };
std::string addrtype { "IP4" }; std::string addrtype { "IP4" };
std::string address { "0.0.0.0" }; std::string address { "0.0.0.0" };
void parse(const std::string &str) override;; void parse(const std::string &str) override;
;
std::string toString() const override; std::string toString() const override;
const char *getKey() const override { return "rtcp"; } const char *getKey() const override { return "rtcp"; }
bool empty() const { bool empty() const { return address.empty() || !port; }
return address.empty() || !port;
}
}; };
class SdpAttrIceUfrag : public SdpItem { class SdpAttrIceUfrag : public SdpItem {
@ -364,9 +351,9 @@ public:
// a=rtcp-fb:98 nack pli // a=rtcp-fb:98 nack pli
// a=rtcp-fb:120 nack 支持 nack 重传nack (Negative-Acknowledgment) 。 // a=rtcp-fb:120 nack 支持 nack 重传nack (Negative-Acknowledgment) 。
// a=rtcp-fb:120 nack pli 支持 nack 关键帧重传PLI (Picture Loss Indication) 。 // a=rtcp-fb:120 nack pli 支持 nack 关键帧重传PLI (Picture Loss Indication) 。
//a=rtcp-fb:120 ccm fir 支持编码层关键帧请求CCM (Codec Control Message)FIR (Full Intra Request ),通常与 nack pli 有同样的效果,但是 nack pli 是用于重传时的关键帧请求。 // a=rtcp-fb:120 ccm fir 支持编码层关键帧请求CCM (Codec Control Message)FIR (Full Intra Request ),通常与 nack pli 有同样的效果,但是 nack pli
//a=rtcp-fb:120 goog-remb 支持 REMB (Receiver Estimated Maximum Bitrate) 。 // 是用于重传时的关键帧请求。 a=rtcp-fb:120 goog-remb 支持 REMB (Receiver Estimated Maximum Bitrate) 。 a=rtcp-fb:120 transport-cc 支持 TCC (Transport
//a=rtcp-fb:120 transport-cc 支持 TCC (Transport Congest Control) 。 // Congest Control) 。
uint8_t pt; uint8_t pt;
std::string rtcp_type; std::string rtcp_type;
void parse(const std::string &str) override; void parse(const std::string &str) override;