OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 std::string* message); | 261 std::string* message); |
262 static void BuildCandidate(const std::vector<Candidate>& candidates, | 262 static void BuildCandidate(const std::vector<Candidate>& candidates, |
263 std::string* message); | 263 std::string* message); |
264 static void BuildIceOptions(const std::vector<std::string>& transport_options, | 264 static void BuildIceOptions(const std::vector<std::string>& transport_options, |
265 std::string* message); | 265 std::string* message); |
266 static bool IsRtp(const std::string& protocol); | 266 static bool IsRtp(const std::string& protocol); |
267 static bool IsDtlsSctp(const std::string& protocol); | 267 static bool IsDtlsSctp(const std::string& protocol); |
268 static bool ParseSessionDescription(const std::string& message, size_t* pos, | 268 static bool ParseSessionDescription(const std::string& message, size_t* pos, |
269 std::string* session_id, | 269 std::string* session_id, |
270 std::string* session_version, | 270 std::string* session_version, |
271 bool* supports_msid, | |
272 TransportDescription* session_td, | 271 TransportDescription* session_td, |
273 RtpHeaderExtensions* session_extmaps, | 272 RtpHeaderExtensions* session_extmaps, |
274 cricket::SessionDescription* desc, | 273 cricket::SessionDescription* desc, |
275 SdpParseError* error); | 274 SdpParseError* error); |
276 static bool ParseGroupAttribute(const std::string& line, | 275 static bool ParseGroupAttribute(const std::string& line, |
277 cricket::SessionDescription* desc, | 276 cricket::SessionDescription* desc, |
278 SdpParseError* error); | 277 SdpParseError* error); |
279 static bool ParseMediaDescription( | 278 static bool ParseMediaDescription( |
280 const std::string& message, | 279 const std::string& message, |
281 const TransportDescription& session_td, | 280 const TransportDescription& session_td, |
282 const RtpHeaderExtensions& session_extmaps, | 281 const RtpHeaderExtensions& session_extmaps, |
283 bool supports_msid, | |
284 size_t* pos, cricket::SessionDescription* desc, | 282 size_t* pos, cricket::SessionDescription* desc, |
285 std::vector<JsepIceCandidate*>* candidates, | 283 std::vector<JsepIceCandidate*>* candidates, |
286 SdpParseError* error); | 284 SdpParseError* error); |
287 static bool ParseContent(const std::string& message, | 285 static bool ParseContent(const std::string& message, |
288 const MediaType media_type, | 286 const MediaType media_type, |
289 int mline_index, | 287 int mline_index, |
290 const std::string& protocol, | 288 const std::string& protocol, |
291 const std::vector<int>& codec_preference, | 289 const std::vector<int>& codec_preference, |
292 size_t* pos, | 290 size_t* pos, |
293 std::string* content_name, | 291 std::string* content_name, |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 bool SdpDeserialize(const std::string& message, | 889 bool SdpDeserialize(const std::string& message, |
892 JsepSessionDescription* jdesc, | 890 JsepSessionDescription* jdesc, |
893 SdpParseError* error) { | 891 SdpParseError* error) { |
894 std::string session_id; | 892 std::string session_id; |
895 std::string session_version; | 893 std::string session_version; |
896 TransportDescription session_td("", ""); | 894 TransportDescription session_td("", ""); |
897 RtpHeaderExtensions session_extmaps; | 895 RtpHeaderExtensions session_extmaps; |
898 cricket::SessionDescription* desc = new cricket::SessionDescription(); | 896 cricket::SessionDescription* desc = new cricket::SessionDescription(); |
899 std::vector<JsepIceCandidate*> candidates; | 897 std::vector<JsepIceCandidate*> candidates; |
900 size_t current_pos = 0; | 898 size_t current_pos = 0; |
901 bool supports_msid = false; | |
902 | 899 |
903 // Session Description | 900 // Session Description |
904 if (!ParseSessionDescription(message, ¤t_pos, &session_id, | 901 if (!ParseSessionDescription(message, ¤t_pos, &session_id, |
905 &session_version, &supports_msid, &session_td, | 902 &session_version, &session_td, &session_extmaps, |
906 &session_extmaps, desc, error)) { | 903 desc, error)) { |
907 delete desc; | 904 delete desc; |
908 return false; | 905 return false; |
909 } | 906 } |
910 | 907 |
911 // Media Description | 908 // Media Description |
912 if (!ParseMediaDescription(message, session_td, session_extmaps, | 909 if (!ParseMediaDescription(message, session_td, session_extmaps, ¤t_pos, |
913 supports_msid, ¤t_pos, desc, &candidates, | 910 desc, &candidates, error)) { |
914 error)) { | |
915 delete desc; | 911 delete desc; |
916 for (std::vector<JsepIceCandidate*>::const_iterator | 912 for (std::vector<JsepIceCandidate*>::const_iterator |
917 it = candidates.begin(); it != candidates.end(); ++it) { | 913 it = candidates.begin(); it != candidates.end(); ++it) { |
918 delete *it; | 914 delete *it; |
919 } | 915 } |
920 return false; | 916 return false; |
921 } | 917 } |
922 | 918 |
923 jdesc->Initialize(desc, session_id, session_version); | 919 jdesc->Initialize(desc, session_id, session_version); |
924 | 920 |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1372 // implementation uses all media level. | 1368 // implementation uses all media level. |
1373 for (size_t i = 0; i < media_desc->rtp_header_extensions().size(); ++i) { | 1369 for (size_t i = 0; i < media_desc->rtp_header_extensions().size(); ++i) { |
1374 InitAttrLine(kAttributeExtmap, &os); | 1370 InitAttrLine(kAttributeExtmap, &os); |
1375 os << kSdpDelimiterColon << media_desc->rtp_header_extensions()[i].id | 1371 os << kSdpDelimiterColon << media_desc->rtp_header_extensions()[i].id |
1376 << kSdpDelimiterSpace << media_desc->rtp_header_extensions()[i].uri; | 1372 << kSdpDelimiterSpace << media_desc->rtp_header_extensions()[i].uri; |
1377 AddLine(os.str(), message); | 1373 AddLine(os.str(), message); |
1378 } | 1374 } |
1379 | 1375 |
1380 // RFC 3264 | 1376 // RFC 3264 |
1381 // a=sendrecv || a=sendonly || a=sendrecv || a=inactive | 1377 // a=sendrecv || a=sendonly || a=sendrecv || a=inactive |
1382 | 1378 switch (media_desc->direction()) { |
1383 cricket::MediaContentDirection direction = media_desc->direction(); | |
1384 if (media_desc->streams().empty() && direction == cricket::MD_SENDRECV) { | |
1385 direction = cricket::MD_RECVONLY; | |
1386 } | |
1387 | |
1388 switch (direction) { | |
1389 case cricket::MD_INACTIVE: | 1379 case cricket::MD_INACTIVE: |
1390 InitAttrLine(kAttributeInactive, &os); | 1380 InitAttrLine(kAttributeInactive, &os); |
1391 break; | 1381 break; |
1392 case cricket::MD_SENDONLY: | 1382 case cricket::MD_SENDONLY: |
1393 InitAttrLine(kAttributeSendOnly, &os); | 1383 InitAttrLine(kAttributeSendOnly, &os); |
1394 break; | 1384 break; |
1395 case cricket::MD_RECVONLY: | 1385 case cricket::MD_RECVONLY: |
1396 InitAttrLine(kAttributeRecvOnly, &os); | 1386 InitAttrLine(kAttributeRecvOnly, &os); |
1397 break; | 1387 break; |
1398 case cricket::MD_SENDRECV: | 1388 case cricket::MD_SENDRECV: |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1791 } | 1781 } |
1792 | 1782 |
1793 bool IsDtlsSctp(const std::string& protocol) { | 1783 bool IsDtlsSctp(const std::string& protocol) { |
1794 // This intentionally excludes "SCTP" and "SCTP/DTLS". | 1784 // This intentionally excludes "SCTP" and "SCTP/DTLS". |
1795 return protocol.find(cricket::kMediaProtocolDtlsSctp) != std::string::npos; | 1785 return protocol.find(cricket::kMediaProtocolDtlsSctp) != std::string::npos; |
1796 } | 1786 } |
1797 | 1787 |
1798 bool ParseSessionDescription(const std::string& message, size_t* pos, | 1788 bool ParseSessionDescription(const std::string& message, size_t* pos, |
1799 std::string* session_id, | 1789 std::string* session_id, |
1800 std::string* session_version, | 1790 std::string* session_version, |
1801 bool* supports_msid, | |
1802 TransportDescription* session_td, | 1791 TransportDescription* session_td, |
1803 RtpHeaderExtensions* session_extmaps, | 1792 RtpHeaderExtensions* session_extmaps, |
1804 cricket::SessionDescription* desc, | 1793 cricket::SessionDescription* desc, |
1805 SdpParseError* error) { | 1794 SdpParseError* error) { |
1806 std::string line; | 1795 std::string line; |
1807 | 1796 |
1797 desc->set_msid_supported(false); | |
1798 | |
1808 // RFC 4566 | 1799 // RFC 4566 |
1809 // v= (protocol version) | 1800 // v= (protocol version) |
1810 if (!GetLineWithType(message, pos, &line, kLineTypeVersion)) { | 1801 if (!GetLineWithType(message, pos, &line, kLineTypeVersion)) { |
1811 return ParseFailedExpectLine(message, *pos, kLineTypeVersion, | 1802 return ParseFailedExpectLine(message, *pos, kLineTypeVersion, |
1812 std::string(), error); | 1803 std::string(), error); |
1813 } | 1804 } |
1814 // RFC 4566 | 1805 // RFC 4566 |
1815 // o=<username> <sess-id> <sess-version> <nettype> <addrtype> | 1806 // o=<username> <sess-id> <sess-version> <nettype> <addrtype> |
1816 // <unicast-address> | 1807 // <unicast-address> |
1817 if (!GetLineWithType(message, pos, &line, kLineTypeOrigin)) { | 1808 if (!GetLineWithType(message, pos, &line, kLineTypeOrigin)) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1929 session_td->identity_fingerprint.reset(fingerprint); | 1920 session_td->identity_fingerprint.reset(fingerprint); |
1930 } else if (HasAttribute(line, kAttributeSetup)) { | 1921 } else if (HasAttribute(line, kAttributeSetup)) { |
1931 if (!ParseDtlsSetup(line, &(session_td->connection_role), error)) { | 1922 if (!ParseDtlsSetup(line, &(session_td->connection_role), error)) { |
1932 return false; | 1923 return false; |
1933 } | 1924 } |
1934 } else if (HasAttribute(line, kAttributeMsidSemantics)) { | 1925 } else if (HasAttribute(line, kAttributeMsidSemantics)) { |
1935 std::string semantics; | 1926 std::string semantics; |
1936 if (!GetValue(line, kAttributeMsidSemantics, &semantics, error)) { | 1927 if (!GetValue(line, kAttributeMsidSemantics, &semantics, error)) { |
1937 return false; | 1928 return false; |
1938 } | 1929 } |
1939 *supports_msid = CaseInsensitiveFind(semantics, kMediaStreamSemantic); | 1930 desc->set_msid_supported( |
1931 CaseInsensitiveFind(semantics, kMediaStreamSemantic)); | |
1940 } else if (HasAttribute(line, kAttributeExtmap)) { | 1932 } else if (HasAttribute(line, kAttributeExtmap)) { |
1941 RtpHeaderExtension extmap; | 1933 RtpHeaderExtension extmap; |
1942 if (!ParseExtmap(line, &extmap, error)) { | 1934 if (!ParseExtmap(line, &extmap, error)) { |
1943 return false; | 1935 return false; |
1944 } | 1936 } |
1945 session_extmaps->push_back(extmap); | 1937 session_extmaps->push_back(extmap); |
1946 } | 1938 } |
1947 } | 1939 } |
1948 | 1940 |
1949 return true; | 1941 return true; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2139 return NULL; | 2131 return NULL; |
2140 } | 2132 } |
2141 // Sort the codecs according to the m-line fmt list. | 2133 // Sort the codecs according to the m-line fmt list. |
2142 media_desc->SortCodecs(); | 2134 media_desc->SortCodecs(); |
2143 return media_desc; | 2135 return media_desc; |
2144 } | 2136 } |
2145 | 2137 |
2146 bool ParseMediaDescription(const std::string& message, | 2138 bool ParseMediaDescription(const std::string& message, |
2147 const TransportDescription& session_td, | 2139 const TransportDescription& session_td, |
2148 const RtpHeaderExtensions& session_extmaps, | 2140 const RtpHeaderExtensions& session_extmaps, |
2149 bool supports_msid, | |
2150 size_t* pos, | 2141 size_t* pos, |
2151 cricket::SessionDescription* desc, | 2142 cricket::SessionDescription* desc, |
2152 std::vector<JsepIceCandidate*>* candidates, | 2143 std::vector<JsepIceCandidate*>* candidates, |
2153 SdpParseError* error) { | 2144 SdpParseError* error) { |
2154 ASSERT(desc != NULL); | 2145 ASSERT(desc != NULL); |
2155 std::string line; | 2146 std::string line; |
2156 int mline_index = -1; | 2147 int mline_index = -1; |
2157 | 2148 |
2158 // Zero or more media descriptions | 2149 // Zero or more media descriptions |
2159 // RFC 4566 | 2150 // RFC 4566 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2234 } else { | 2225 } else { |
2235 LOG(LS_WARNING) << "Unsupported media type: " << line; | 2226 LOG(LS_WARNING) << "Unsupported media type: " << line; |
2236 continue; | 2227 continue; |
2237 } | 2228 } |
2238 if (!content.get()) { | 2229 if (!content.get()) { |
2239 // ParseContentDescription returns NULL if failed. | 2230 // ParseContentDescription returns NULL if failed. |
2240 return false; | 2231 return false; |
2241 } | 2232 } |
2242 | 2233 |
2243 if (IsRtp(protocol)) { | 2234 if (IsRtp(protocol)) { |
2244 // Make sure to set the media direction correctly. If the direction is not | |
2245 // MD_RECVONLY or Inactive and no streams are parsed, | |
2246 // a default MediaStream will be created to prepare for receiving media. | |
2247 if (supports_msid && content->streams().empty() && | |
2248 content->direction() == cricket::MD_SENDRECV) { | |
2249 content->set_direction(cricket::MD_RECVONLY); | |
2250 } | |
Taylor Brandstetter
2015/10/14 23:24:22
This logic is replaced by the "msid_supported" che
| |
2251 | |
2252 // Set the extmap. | 2235 // Set the extmap. |
2253 if (!session_extmaps.empty() && | 2236 if (!session_extmaps.empty() && |
2254 !content->rtp_header_extensions().empty()) { | 2237 !content->rtp_header_extensions().empty()) { |
2255 return ParseFailed("", | 2238 return ParseFailed("", |
2256 "The a=extmap MUST be either all session level or " | 2239 "The a=extmap MUST be either all session level or " |
2257 "all media level.", | 2240 "all media level.", |
2258 error); | 2241 error); |
2259 } | 2242 } |
2260 for (size_t i = 0; i < session_extmaps.size(); ++i) { | 2243 for (size_t i = 0; i < session_extmaps.size(); ++i) { |
2261 content->AddRtpHeaderExtension(session_extmaps[i]); | 2244 content->AddRtpHeaderExtension(session_extmaps[i]); |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3073 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( | 3056 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( |
3074 media_desc, payload_type, feedback_param); | 3057 media_desc, payload_type, feedback_param); |
3075 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 3058 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
3076 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( | 3059 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( |
3077 media_desc, payload_type, feedback_param); | 3060 media_desc, payload_type, feedback_param); |
3078 } | 3061 } |
3079 return true; | 3062 return true; |
3080 } | 3063 } |
3081 | 3064 |
3082 } // namespace webrtc | 3065 } // namespace webrtc |
OLD | NEW |