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

View File

@ -77,11 +77,7 @@ enum class DtlsRole {
actpass,
};
enum class SdpType {
invalid = -1,
offer,
answer
};
enum class SdpType { invalid = -1, offer, answer };
DtlsRole getDtlsRole(const std::string &str);
const char *getDtlsRoleString(DtlsRole role);
@ -92,17 +88,11 @@ class SdpItem {
public:
using Ptr = std::shared_ptr<SdpItem>;
virtual ~SdpItem() = default;
virtual void parse(const std::string &str) {
value = str;
}
virtual std::string toString() const {
return value;
}
virtual void parse(const std::string &str) { value = str; }
virtual std::string toString() const { return value; }
virtual const char *getKey() const = 0;
void reset() {
value.clear();
}
void reset() { value.clear(); }
protected:
mutable std::string value;
@ -259,9 +249,7 @@ public:
void parse(const std::string &str) override;
std::string toString() const override;
const char *getKey() const override { return "msid-semantic"; }
bool empty() const {
return msid.empty();
}
bool empty() const { return msid.empty(); }
};
class SdpAttrRtcp : public SdpItem {
@ -271,12 +259,11 @@ public:
std::string nettype { "IN" };
std::string addrtype { "IP4" };
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;
const char *getKey() const override { return "rtcp"; }
bool empty() const {
return address.empty() || !port;
}
bool empty() const { return address.empty() || !port; }
};
class SdpAttrIceUfrag : public SdpItem {
@ -364,9 +351,9 @@ public:
// a=rtcp-fb:98 nack pli
// a=rtcp-fb:120 nack 支持 nack 重传nack (Negative-Acknowledgment) 。
// 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 goog-remb 支持 REMB (Receiver Estimated Maximum Bitrate) 。
//a=rtcp-fb:120 transport-cc 支持 TCC (Transport Congest Control) 。
// 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 transport-cc 支持 TCC (Transport
// Congest Control) 。
uint8_t pt;
std::string rtcp_type;
void parse(const std::string &str) override;