|
|
|
@ -36,12 +36,12 @@ using namespace std;
|
|
|
|
|
const std::string kCRLF = "\\r\\n";
|
|
|
|
|
|
|
|
|
|
#define FETCH(is,word) \
|
|
|
|
|
if (! (is >> word)) {\
|
|
|
|
|
if (!(is >> word)) {\
|
|
|
|
|
return srs_error_new(ERROR_RTC_SDP_DECODE, "fetch failed");\
|
|
|
|
|
}\
|
|
|
|
|
|
|
|
|
|
#define FETCH_WITH_DELIM(is,word,delim) \
|
|
|
|
|
if (! getline(is,word,delim)) {\
|
|
|
|
|
if (!getline(is,word,delim)) {\
|
|
|
|
|
return srs_error_new(ERROR_RTC_SDP_DECODE, "fetch with delim failed");\
|
|
|
|
|
}\
|
|
|
|
|
|
|
|
|
@ -111,6 +111,7 @@ SrsSessionInfo::~SrsSessionInfo()
|
|
|
|
|
srs_error_t SrsSessionInfo::parse_attribute(const std::string& attribute, const std::string& value)
|
|
|
|
|
{
|
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
|
|
|
|
|
if (attribute == "ice-ufrag") {
|
|
|
|
|
ice_ufrag_ = value;
|
|
|
|
|
} else if (attribute == "ice-pwd") {
|
|
|
|
@ -134,23 +135,25 @@ srs_error_t SrsSessionInfo::parse_attribute(const std::string& attribute, const
|
|
|
|
|
srs_error_t SrsSessionInfo::encode(std::ostringstream& os)
|
|
|
|
|
{
|
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
if (! ice_ufrag_.empty()) {
|
|
|
|
|
|
|
|
|
|
if (!ice_ufrag_.empty()) {
|
|
|
|
|
os << "a=ice-ufrag:" << ice_ufrag_ << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
if (! ice_pwd_.empty()) {
|
|
|
|
|
|
|
|
|
|
if (!ice_pwd_.empty()) {
|
|
|
|
|
os << "a=ice-pwd:" << ice_pwd_ << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
if (! ice_options_.empty()) {
|
|
|
|
|
|
|
|
|
|
// For ICE-lite, we never set the trickle.
|
|
|
|
|
if (!ice_options_.empty()) {
|
|
|
|
|
os << "a=ice-options:" << ice_options_ << kCRLF;
|
|
|
|
|
} else {
|
|
|
|
|
// @see: https://webrtcglossary.com/trickle-ice/
|
|
|
|
|
// Trickle ICE is an optimization of the ICE specification for NAT traversal.
|
|
|
|
|
os << "a=ice-options:trickle" << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
if (! fingerprint_algo_.empty() && ! fingerprint_.empty()) {
|
|
|
|
|
|
|
|
|
|
if (!fingerprint_algo_.empty() && ! fingerprint_.empty()) {
|
|
|
|
|
os << "a=fingerprint:" << fingerprint_algo_ << " " << fingerprint_ << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
if (! setup_.empty()) {
|
|
|
|
|
|
|
|
|
|
if (!setup_.empty()) {
|
|
|
|
|
os << "a=setup:" << setup_ << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -179,22 +182,23 @@ SrsSSRCInfo::~SrsSSRCInfo()
|
|
|
|
|
srs_error_t SrsSSRCInfo::encode(std::ostringstream& os)
|
|
|
|
|
{
|
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
|
|
|
|
|
if (ssrc_ == 0) {
|
|
|
|
|
return srs_error_new(ERROR_RTC_SDP_DECODE, "invalid ssrc");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
os << "a=ssrc:" << ssrc_ << " cname:" << cname_ << kCRLF;
|
|
|
|
|
if (! msid_.empty()) {
|
|
|
|
|
if (!msid_.empty()) {
|
|
|
|
|
os << "a=ssrc:" << ssrc_ << " msid:" << msid_;
|
|
|
|
|
if (! msid_tracker_.empty()) {
|
|
|
|
|
if (!msid_tracker_.empty()) {
|
|
|
|
|
os << " " << msid_tracker_;
|
|
|
|
|
}
|
|
|
|
|
os << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
if (! mslabel_.empty()) {
|
|
|
|
|
if (!mslabel_.empty()) {
|
|
|
|
|
os << "a=ssrc:" << ssrc_ << " mslabel:" << mslabel_ << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
if (! label_.empty()) {
|
|
|
|
|
if (!label_.empty()) {
|
|
|
|
|
os << "a=ssrc:" << ssrc_ << " label:" << label_ << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -215,7 +219,7 @@ srs_error_t SrsMediaPayloadType::encode(std::ostringstream& os)
|
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
|
|
|
|
|
os << "a=rtpmap:" << payload_type_ << " " << encoding_name_ << "/" << clock_rate_;
|
|
|
|
|
if (! encoding_param_.empty()) {
|
|
|
|
|
if (!encoding_param_.empty()) {
|
|
|
|
|
os << "/" << encoding_param_;
|
|
|
|
|
}
|
|
|
|
|
os << kCRLF;
|
|
|
|
@ -224,7 +228,7 @@ srs_error_t SrsMediaPayloadType::encode(std::ostringstream& os)
|
|
|
|
|
os << "a=rtcp-fb:" << payload_type_ << " " << *iter << kCRLF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! format_specific_param_.empty()) {
|
|
|
|
|
if (!format_specific_param_.empty()) {
|
|
|
|
|
os << "a=fmtp:" << payload_type_ << " " << format_specific_param_
|
|
|
|
|
// TODO: FIXME: Remove the test code bellow.
|
|
|
|
|
// << ";x-google-max-bitrate=6000;x-google-min-bitrate=5100;x-google-start-bitrate=5000"
|
|
|
|
@ -315,10 +319,10 @@ srs_error_t SrsMediaDesc::encode(std::ostringstream& os)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
os << "a=mid:" << mid_ << kCRLF;
|
|
|
|
|
if (! msid_.empty()) {
|
|
|
|
|
if (!msid_.empty()) {
|
|
|
|
|
os << "a=msid:" << msid_;
|
|
|
|
|
|
|
|
|
|
if (! msid_tracker_.empty()) {
|
|
|
|
|
if (!msid_tracker_.empty()) {
|
|
|
|
|
os << " " << msid_tracker_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -658,7 +662,7 @@ srs_error_t SrsSdp::parse(const std::string& sdp_str)
|
|
|
|
|
if (line.size() < 2 || line[1] != '=') {
|
|
|
|
|
return srs_error_new(ERROR_RTC_SDP_DECODE, "invalid sdp line=%s", line.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (! line.empty() && line[line.size()-1] == '\r') {
|
|
|
|
|
if (!line.empty() && line[line.size()-1] == '\r') {
|
|
|
|
|
line.erase(line.size()-1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -681,7 +685,7 @@ srs_error_t SrsSdp::encode(std::ostringstream& os)
|
|
|
|
|
// ice-lite is a minimal version of the ICE specification, intended for servers running on a public IP address.
|
|
|
|
|
os << "a=ice-lite" << kCRLF;
|
|
|
|
|
|
|
|
|
|
if (! groups_.empty()) {
|
|
|
|
|
if (!groups_.empty()) {
|
|
|
|
|
os << "a=group:" << group_policy_;
|
|
|
|
|
for (std::vector<std::string>::iterator iter = groups_.begin(); iter != groups_.end(); ++iter) {
|
|
|
|
|
os << " " << *iter;
|
|
|
|
@ -954,7 +958,7 @@ srs_error_t SrsSdp::parse_media_description(const std::string& content)
|
|
|
|
|
media_descs_.back().payload_types_.push_back(SrsMediaPayloadType(fmt));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! in_media_session_) {
|
|
|
|
|
if (!in_media_session_) {
|
|
|
|
|
in_media_session_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|