Skip to content

Commit 4ad4dd0

Browse files
committed
RTC: Refine SDP to support GB28181 SSRC spec. v5.0.71
1 parent d32bd72 commit 4ad4dd0

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

trunk/doc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77

88
## SRS 5.0 Changelog
99

10+
* v5.0, 2022-09-30, RTC: Refine SDP to support GB28181 SSRC spec. v5.0.71
1011
* v5.0, 2022-09-30, GB28181: Refine HTTP parser to support SIP. v5.0.70
1112
* v5.0, 2022-09-30, Kernel: Support lazy sweeping simple GC. v5.0.69
1213
* v5.0, 2022-09-30, HTTP: Support HTTP header in creating order. v5.0.68

trunk/src/app/srs_app_rtc_sdp.cpp

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ srs_error_t SrsSSRCInfo::encode(std::ostringstream& os)
199199
return srs_error_new(ERROR_RTC_SDP_DECODE, "invalid ssrc");
200200
}
201201

202+
// See AnnexF at page 101 of https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=469659DC56B9B8187671FF08748CEC89
203+
// Encode the bellow format:
204+
// a=ssrc:0100008888 cname:0100008888
205+
// a=ssrc:0100008888 label:gb28181
206+
// As GB28181 format:
207+
// y=0100008888
208+
if (label_ == "gb28181") {
209+
os << "y=" << (cname_.empty() ? srs_fmt("%u", ssrc_) : cname_) << kCRLF;
210+
return err;
211+
}
212+
202213
os << "a=ssrc:" << ssrc_ << " cname:" << cname_ << kCRLF;
203214
if (!msid_.empty()) {
204215
os << "a=ssrc:" << ssrc_ << " msid:" << msid_;
@@ -297,6 +308,8 @@ SrsMediaDesc::SrsMediaDesc(const std::string& type)
297308
recvonly_ = false;
298309
sendonly_ = false;
299310
inactive_ = false;
311+
312+
connection_ = "c=IN IP4 0.0.0.0";
300313
}
301314

302315
SrsMediaDesc::~SrsMediaDesc()
@@ -380,13 +393,13 @@ srs_error_t SrsMediaDesc::encode(std::ostringstream& os)
380393
os << kCRLF;
381394

382395
// TODO:nettype and address type
383-
os << "c=IN IP4 0.0.0.0" << kCRLF;
396+
if (!connection_.empty()) os << connection_ << kCRLF;
384397

385398
if ((err = session_info_.encode(os)) != srs_success) {
386399
return srs_error_wrap(err, "encode session info failed");
387400
}
388401

389-
os << "a=mid:" << mid_ << kCRLF;
402+
if (!mid_.empty()) os << "a=mid:" << mid_ << kCRLF;
390403
if (!msid_.empty()) {
391404
os << "a=msid:" << msid_;
392405

@@ -738,6 +751,8 @@ SrsSdp::SrsSdp()
738751

739752
start_time_ = 0;
740753
end_time_ = 0;
754+
755+
ice_lite_ = "a=ice-lite";
741756
}
742757

743758
SrsSdp::~SrsSdp()
@@ -818,9 +833,12 @@ srs_error_t SrsSdp::encode(std::ostringstream& os)
818833
os << "v=" << version_ << kCRLF;
819834
os << "o=" << username_ << " " << session_id_ << " " << session_version_ << " " << nettype_ << " " << addrtype_ << " " << unicast_address_ << kCRLF;
820835
os << "s=" << session_name_ << kCRLF;
836+
// Session level connection data, see https://www.ietf.org/rfc/rfc4566.html#section-5.7
837+
if (!connection_.empty()) os << connection_ << kCRLF;
838+
// Timing, see https://www.ietf.org/rfc/rfc4566.html#section-5.9
821839
os << "t=" << start_time_ << " " << end_time_ << kCRLF;
822840
// ice-lite is a minimal version of the ICE specification, intended for servers running on a public IP address.
823-
os << "a=ice-lite" << kCRLF;
841+
if (!ice_lite_.empty()) os << ice_lite_ << kCRLF;
824842

825843
if (!groups_.empty()) {
826844
os << "a=group:" << group_policy_;
@@ -830,11 +848,13 @@ srs_error_t SrsSdp::encode(std::ostringstream& os)
830848
os << kCRLF;
831849
}
832850

833-
os << "a=msid-semantic: " << msid_semantic_;
834-
for (std::vector<std::string>::iterator iter = msids_.begin(); iter != msids_.end(); ++iter) {
835-
os << " " << *iter;
851+
if (!msid_semantic_.empty() || !msids_.empty()) {
852+
os << "a=msid-semantic: " << msid_semantic_;
853+
for (std::vector<std::string>::iterator iter = msids_.begin(); iter != msids_.end(); ++iter) {
854+
os << " " << *iter;
855+
}
856+
os << kCRLF;
836857
}
837-
os << kCRLF;
838858

839859
if ((err = session_info_.encode(os)) != srs_success) {
840860
return srs_error_wrap(err, "encode session info failed");
@@ -976,6 +996,9 @@ srs_error_t SrsSdp::parse_line(const std::string& line)
976996
}
977997
return parse_attribute(content);
978998
}
999+
case 'y': {
1000+
return parse_gb28181_ssrc(content);
1001+
}
9791002
case 'm': {
9801003
return parse_media_description(content);
9811004
}
@@ -1081,6 +1104,29 @@ srs_error_t SrsSdp::parse_attribute(const std::string& content)
10811104
return err;
10821105
}
10831106

1107+
srs_error_t SrsSdp::parse_gb28181_ssrc(const std::string& content)
1108+
{
1109+
srs_error_t err = srs_success;
1110+
1111+
// See AnnexF at page 101 of https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=469659DC56B9B8187671FF08748CEC89
1112+
// Convert SSRC of GB28181 from:
1113+
// y=0100008888
1114+
// to standard format:
1115+
// a=ssrc:0100008888 cname:0100008888
1116+
// a=ssrc:0100008888 label:gb28181
1117+
string cname = srs_fmt("a=ssrc:%s cname:%s", content.c_str(), content.c_str());
1118+
if ((err = media_descs_.back().parse_line(cname)) != srs_success) {
1119+
return srs_error_wrap(err, "parse gb %s cname", content.c_str());
1120+
}
1121+
1122+
string label = srs_fmt("a=ssrc:%s label:gb28181", content.c_str());
1123+
if ((err = media_descs_.back().parse_line(label)) != srs_success) {
1124+
return srs_error_wrap(err, "parse gb %s label", content.c_str());
1125+
}
1126+
1127+
return err;
1128+
}
1129+
10841130
srs_error_t SrsSdp::parse_attr_group(const std::string& value)
10851131
{
10861132
srs_error_t err = srs_success;

trunk/src/app/srs_app_rtc_sdp.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class SrsMediaDesc
172172
std::string msid_tracker_;
173173
std::string protos_;
174174
std::vector<SrsMediaPayloadType> payload_types_;
175+
std::string connection_;
175176

176177
std::vector<SrsCandidate> candidates_;
177178
std::vector<SrsSSRCGroup> ssrc_groups_;
@@ -208,6 +209,7 @@ class SrsSdp
208209
srs_error_t parse_session_name(const std::string& content);
209210
srs_error_t parse_timing(const std::string& content);
210211
srs_error_t parse_attribute(const std::string& content);
212+
srs_error_t parse_gb28181_ssrc(const std::string& content);
211213
srs_error_t parse_media_description(const std::string& content);
212214
srs_error_t parse_attr_group(const std::string& content);
213215
private:
@@ -231,13 +233,17 @@ class SrsSdp
231233
int64_t start_time_;
232234
int64_t end_time_;
233235

236+
// Connection data, see https://www.ietf.org/rfc/rfc4566.html#section-5.7
237+
std::string connection_;
238+
234239
SrsSessionInfo session_info_;
235240
SrsSessionConfig session_config_;
236241
SrsSessionConfig session_negotiate_;
237242

238243
std::vector<std::string> groups_;
239244
std::string group_policy_;
240245

246+
std::string ice_lite_;
241247
std::string msid_semantic_;
242248
std::vector<std::string> msids_;
243249

trunk/src/core/srs_core_version5.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 70
12+
#define VERSION_REVISION 71
1313

1414
#endif

0 commit comments

Comments
 (0)