@@ -218,7 +218,9 @@ void Description::hintType(Type type) {
218
218
219
219
void Description::setFingerprint (CertificateFingerprint f) {
220
220
if (!f.isValid ())
221
- throw std::invalid_argument (" Invalid " + CertificateFingerprint::AlgorithmIdentifier (f.algorithm ) + " fingerprint \" " + f.value + " \" " );
221
+ throw std::invalid_argument (" Invalid " +
222
+ CertificateFingerprint::AlgorithmIdentifier (f.algorithm ) +
223
+ " fingerprint \" " + f.value + " \" " );
222
224
223
225
std::transform (f.value .begin (), f.value .end (), f.value .begin (),
224
226
[](char c) { return char (std::toupper (c)); });
@@ -540,9 +542,11 @@ Description::Entry::Entry(const string &mline, string mid, Direction dir)
540
542
std::istringstream ss (match_prefix (mline, " m=" ) ? mline.substr (2 ) : mline);
541
543
ss >> mType ;
542
544
ss >> port;
543
- ss >> mDescription ;
545
+ ss >> mProtocol ;
546
+ ss >> std::ws;
547
+ std::getline (ss, mDescription );
544
548
545
- if (mType .empty () || mDescription .empty ())
549
+ if (mType .empty () || mProtocol .empty ())
546
550
throw std::invalid_argument (" Invalid media description line" );
547
551
548
552
// RFC 3264: Existing media streams are removed by creating a new SDP with the port number for
@@ -555,6 +559,8 @@ Description::Entry::Entry(const string &mline, string mid, Direction dir)
555
559
556
560
string Description::Entry::type () const { return mType ; }
557
561
562
+ string Description::Entry::protocol () const { return mProtocol ; }
563
+
558
564
string Description::Entry::description () const { return mDescription ; }
559
565
560
566
string Description::Entry::mid () const { return mMid ; }
@@ -621,7 +627,8 @@ string Description::Entry::generateSdp(string_view eol, string_view addr, uint16
621
627
// RFC 3264: Existing media streams are removed by creating a new SDP with the port number for
622
628
// that stream set to zero. [...] A stream that is offered with a port of zero MUST be marked
623
629
// with port zero in the answer.
624
- sdp << " m=" << type () << ' ' << (mIsRemoved ? 0 : port) << ' ' << description () << eol;
630
+ sdp << " m=" << type () << ' ' << (mIsRemoved ? 0 : port) << ' ' << protocol () << ' '
631
+ << description () << eol;
625
632
sdp << " c=IN " << addr << eol;
626
633
sdp << generateSdpLines (eol);
627
634
@@ -825,15 +832,12 @@ optional<string> Description::Media::getCNameForSsrc(uint32_t ssrc) const {
825
832
}
826
833
827
834
Description::Application::Application (string mid)
828
- : Entry(" application 9 UDP/DTLS/SCTP" , std::move(mid), Direction::SendRecv) {}
835
+ : Entry(" application 9 UDP/DTLS/SCTP webrtc-datachannel" , std::move(mid), Direction::SendRecv) {
836
+ }
829
837
830
838
Description::Application::Application (const string &mline, string mid)
831
839
: Entry(mline, std::move(mid), Direction::SendRecv) {}
832
840
833
- string Description::Application::description () const {
834
- return Entry::description () + " webrtc-datachannel" ;
835
- }
836
-
837
841
Description::Application Description::Application::reciprocate () const {
838
842
Application reciprocated (*this );
839
843
@@ -882,7 +886,15 @@ void Description::Application::parseSdpLine(string_view line) {
882
886
}
883
887
}
884
888
885
- Description::Media::Media (const string &sdp) : Entry(get_first_line(sdp), " " , Direction::Unknown) {
889
+ Description::Media::Media (const string &mline, string mid, Direction dir)
890
+ : Entry(mline, std::move(mid), dir) {
891
+ std::istringstream ss (Entry::description ());
892
+ int payloadType;
893
+ while (ss >> payloadType)
894
+ mOrderedPayloadTypes .push_back (payloadType);
895
+ }
896
+
897
+ Description::Media::Media (const string &sdp) : Media(get_first_line(sdp), " " , Direction::Unknown) {
886
898
string line;
887
899
std::istringstream ss (sdp);
888
900
std::getline (ss, line); // discard first line
@@ -899,16 +911,16 @@ Description::Media::Media(const string &sdp) : Entry(get_first_line(sdp), "", Di
899
911
throw std::invalid_argument (" Missing mid in media description" );
900
912
}
901
913
902
- Description::Media::Media (const string &mline, string mid, Direction dir)
903
- : Entry(mline, std::move(mid), dir) {}
904
-
905
914
string Description::Media::description () const {
906
- std::ostringstream desc;
907
- desc << Entry::description ();
908
- for (auto it = mRtpMaps .begin (); it != mRtpMaps .end (); ++it)
909
- desc << ' ' << it->first ;
915
+ std::ostringstream ss;
916
+ for (auto it = mOrderedPayloadTypes .begin (); it != mOrderedPayloadTypes .end (); ++it) {
917
+ if (it != mOrderedPayloadTypes .begin ())
918
+ ss << ' ' ;
919
+
920
+ ss << *it;
921
+ }
910
922
911
- return desc .str ();
923
+ return ss .str ();
912
924
}
913
925
914
926
Description::Media Description::Media::reciprocate () const {
@@ -961,14 +973,7 @@ bool Description::Media::hasPayloadType(int payloadType) const {
961
973
return mRtpMaps .find (payloadType) != mRtpMaps .end ();
962
974
}
963
975
964
- std::vector<int > Description::Media::payloadTypes () const {
965
- std::vector<int > result;
966
- result.reserve (mRtpMaps .size ());
967
- for (auto it = mRtpMaps .begin (); it != mRtpMaps .end (); ++it)
968
- result.push_back (it->first );
969
-
970
- return result;
971
- }
976
+ std::vector<int > Description::Media::payloadTypes () const { return mOrderedPayloadTypes ; }
972
977
973
978
Description::Media::RtpMap *Description::Media::rtpMap (int payloadType) {
974
979
auto it = mRtpMaps .find (payloadType);
@@ -987,23 +992,34 @@ const Description::Media::RtpMap *Description::Media::rtpMap(int payloadType) co
987
992
}
988
993
989
994
void Description::Media::addRtpMap (RtpMap map) {
990
- auto payloadType = map.payloadType ;
995
+ int payloadType = map.payloadType ;
996
+ if (std::find (mOrderedPayloadTypes .begin (), mOrderedPayloadTypes .end (), payloadType) ==
997
+ mOrderedPayloadTypes .end ())
998
+ mOrderedPayloadTypes .push_back (payloadType);
999
+
991
1000
mRtpMaps .emplace (payloadType, std::move (map));
992
1001
}
993
1002
994
1003
void Description::Media::removeRtpMap (int payloadType) {
995
1004
// Remove the actual format
1005
+ mOrderedPayloadTypes .erase (
1006
+ std::remove (mOrderedPayloadTypes .begin (), mOrderedPayloadTypes .end (), payloadType),
1007
+ mOrderedPayloadTypes .end ());
996
1008
mRtpMaps .erase (payloadType);
997
1009
998
1010
// Remove any other rtpmaps that depend on the format we just removed
999
1011
auto it = mRtpMaps .begin ();
1000
1012
while (it != mRtpMaps .end ()) {
1001
1013
const auto &fmtps = it->second .fmtps ;
1002
1014
if (std::find (fmtps.begin (), fmtps.end (), " apt=" + std::to_string (payloadType)) !=
1003
- fmtps.end ())
1015
+ fmtps.end ()) {
1016
+ mOrderedPayloadTypes .erase (
1017
+ std::remove (mOrderedPayloadTypes .begin (), mOrderedPayloadTypes .end (), it->first ),
1018
+ mOrderedPayloadTypes .end ());
1004
1019
it = mRtpMaps .erase (it);
1005
- else
1020
+ } else {
1006
1021
++it;
1022
+ }
1007
1023
}
1008
1024
}
1009
1025
@@ -1306,8 +1322,8 @@ CertificateFingerprint::AlgorithmSize(CertificateFingerprint::Algorithm fingerpr
1306
1322
return 48 ;
1307
1323
case CertificateFingerprint::Algorithm::Sha512:
1308
1324
return 64 ;
1309
- default :
1310
- return 0 ;
1325
+ default :
1326
+ return 0 ;
1311
1327
}
1312
1328
}
1313
1329
@@ -1325,7 +1341,7 @@ std::string CertificateFingerprint::AlgorithmIdentifier(
1325
1341
case CertificateFingerprint::Algorithm::Sha512:
1326
1342
return " sha-512" ;
1327
1343
default :
1328
- return " unknown" ;
1344
+ return " unknown" ;
1329
1345
}
1330
1346
}
1331
1347
0 commit comments