| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 typedef std::vector<SsrcGroup> SsrcGroupVec; | 227 typedef std::vector<SsrcGroup> SsrcGroupVec; |
| 228 | 228 |
| 229 template <class T> | 229 template <class T> |
| 230 static void AddFmtpLine(const T& codec, std::string* message); | 230 static void AddFmtpLine(const T& codec, std::string* message); |
| 231 static void BuildMediaDescription(const ContentInfo* content_info, | 231 static void BuildMediaDescription(const ContentInfo* content_info, |
| 232 const TransportInfo* transport_info, | 232 const TransportInfo* transport_info, |
| 233 const MediaType media_type, | 233 const MediaType media_type, |
| 234 const std::vector<Candidate>& candidates, | 234 const std::vector<Candidate>& candidates, |
| 235 bool unified_plan_sdp, | 235 bool unified_plan_sdp, |
| 236 std::string* message); | 236 std::string* message); |
| 237 static void BuildSctpContentAttributes(std::string* message, int sctp_port); | 237 static void BuildSctpContentAttributes(std::string* message, |
| 238 int sctp_port, |
| 239 bool use_sctpmap); |
| 238 static void BuildRtpContentAttributes(const MediaContentDescription* media_desc, | 240 static void BuildRtpContentAttributes(const MediaContentDescription* media_desc, |
| 239 const MediaType media_type, | 241 const MediaType media_type, |
| 240 bool unified_plan_sdp, | 242 bool unified_plan_sdp, |
| 241 std::string* message); | 243 std::string* message); |
| 242 static void BuildRtpMap(const MediaContentDescription* media_desc, | 244 static void BuildRtpMap(const MediaContentDescription* media_desc, |
| 243 const MediaType media_type, | 245 const MediaType media_type, |
| 244 std::string* message); | 246 std::string* message); |
| 245 static void BuildCandidate(const std::vector<Candidate>& candidates, | 247 static void BuildCandidate(const std::vector<Candidate>& candidates, |
| 246 bool include_ufrag, | 248 bool include_ufrag, |
| 247 std::string* message); | 249 std::string* message); |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 it != audio_desc->codecs().end(); ++it) { | 1270 it != audio_desc->codecs().end(); ++it) { |
| 1269 fmt.append(" "); | 1271 fmt.append(" "); |
| 1270 fmt.append(rtc::ToString<int>(it->id)); | 1272 fmt.append(rtc::ToString<int>(it->id)); |
| 1271 } | 1273 } |
| 1272 } else if (media_type == cricket::MEDIA_TYPE_DATA) { | 1274 } else if (media_type == cricket::MEDIA_TYPE_DATA) { |
| 1273 const DataContentDescription* data_desc = | 1275 const DataContentDescription* data_desc = |
| 1274 static_cast<const DataContentDescription*>(media_desc); | 1276 static_cast<const DataContentDescription*>(media_desc); |
| 1275 if (IsDtlsSctp(media_desc->protocol())) { | 1277 if (IsDtlsSctp(media_desc->protocol())) { |
| 1276 fmt.append(" "); | 1278 fmt.append(" "); |
| 1277 | 1279 |
| 1278 for (std::vector<cricket::DataCodec>::const_iterator it = | 1280 if (data_desc->use_sctpmap()) { |
| 1279 data_desc->codecs().begin(); | 1281 for (std::vector<cricket::DataCodec>::const_iterator it = |
| 1280 it != data_desc->codecs().end(); ++it) { | 1282 data_desc->codecs().begin(); |
| 1281 if (cricket::CodecNamesEq(it->name, cricket::kGoogleSctpDataCodecName) | 1283 it != data_desc->codecs().end(); ++it) { |
| 1282 && it->GetParam(cricket::kCodecParamPort, &sctp_port)) { | 1284 if (cricket::CodecNamesEq(it->name, |
| 1283 break; | 1285 cricket::kGoogleSctpDataCodecName) && |
| 1286 it->GetParam(cricket::kCodecParamPort, &sctp_port)) { |
| 1287 break; |
| 1288 } |
| 1284 } | 1289 } |
| 1290 |
| 1291 fmt.append(rtc::ToString<int>(sctp_port)); |
| 1292 } else { |
| 1293 fmt.append(kDefaultSctpmapProtocol); |
| 1285 } | 1294 } |
| 1286 | |
| 1287 fmt.append(rtc::ToString<int>(sctp_port)); | |
| 1288 } else { | 1295 } else { |
| 1289 for (std::vector<cricket::DataCodec>::const_iterator it = | 1296 for (std::vector<cricket::DataCodec>::const_iterator it = |
| 1290 data_desc->codecs().begin(); | 1297 data_desc->codecs().begin(); |
| 1291 it != data_desc->codecs().end(); ++it) { | 1298 it != data_desc->codecs().end(); ++it) { |
| 1292 fmt.append(" "); | 1299 fmt.append(" "); |
| 1293 fmt.append(rtc::ToString<int>(it->id)); | 1300 fmt.append(rtc::ToString<int>(it->id)); |
| 1294 } | 1301 } |
| 1295 } | 1302 } |
| 1296 } | 1303 } |
| 1297 // The fmt must never be empty. If no codecs are found, set the fmt attribute | 1304 // The fmt must never be empty. If no codecs are found, set the fmt attribute |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 | 1407 |
| 1401 // RFC 3388 | 1408 // RFC 3388 |
| 1402 // mid-attribute = "a=mid:" identification-tag | 1409 // mid-attribute = "a=mid:" identification-tag |
| 1403 // identification-tag = token | 1410 // identification-tag = token |
| 1404 // Use the content name as the mid identification-tag. | 1411 // Use the content name as the mid identification-tag. |
| 1405 InitAttrLine(kAttributeMid, &os); | 1412 InitAttrLine(kAttributeMid, &os); |
| 1406 os << kSdpDelimiterColon << content_info->name; | 1413 os << kSdpDelimiterColon << content_info->name; |
| 1407 AddLine(os.str(), message); | 1414 AddLine(os.str(), message); |
| 1408 | 1415 |
| 1409 if (IsDtlsSctp(media_desc->protocol())) { | 1416 if (IsDtlsSctp(media_desc->protocol())) { |
| 1410 BuildSctpContentAttributes(message, sctp_port); | 1417 const DataContentDescription* data_desc = |
| 1418 static_cast<const DataContentDescription*>(media_desc); |
| 1419 bool use_sctpmap = data_desc->use_sctpmap(); |
| 1420 BuildSctpContentAttributes(message, sctp_port, use_sctpmap); |
| 1411 } else if (IsRtp(media_desc->protocol())) { | 1421 } else if (IsRtp(media_desc->protocol())) { |
| 1412 BuildRtpContentAttributes(media_desc, media_type, unified_plan_sdp, | 1422 BuildRtpContentAttributes(media_desc, media_type, unified_plan_sdp, |
| 1413 message); | 1423 message); |
| 1414 } | 1424 } |
| 1415 } | 1425 } |
| 1416 | 1426 |
| 1417 void BuildSctpContentAttributes(std::string* message, int sctp_port) { | 1427 void BuildSctpContentAttributes(std::string* message, |
| 1418 // draft-ietf-mmusic-sctp-sdp-04 | 1428 int sctp_port, |
| 1419 // a=sctpmap:sctpmap-number protocol [streams] | 1429 bool use_sctpmap) { |
| 1420 // TODO(lally): switch this over to mmusic-sctp-sdp-12 (or later), with | |
| 1421 // 'a=sctp-port:' | |
| 1422 std::ostringstream os; | 1430 std::ostringstream os; |
| 1423 InitAttrLine(kAttributeSctpmap, &os); | 1431 if (use_sctpmap) { |
| 1424 os << kSdpDelimiterColon << sctp_port << kSdpDelimiterSpace | 1432 // draft-ietf-mmusic-sctp-sdp-04 |
| 1425 << kDefaultSctpmapProtocol << kSdpDelimiterSpace | 1433 // a=sctpmap:sctpmap-number protocol [streams] |
| 1426 << cricket::kMaxSctpStreams; | 1434 InitAttrLine(kAttributeSctpmap, &os); |
| 1435 os << kSdpDelimiterColon << sctp_port << kSdpDelimiterSpace |
| 1436 << kDefaultSctpmapProtocol << kSdpDelimiterSpace |
| 1437 << cricket::kMaxSctpStreams; |
| 1438 } else { |
| 1439 // draft-ietf-mmusic-sctp-sdp-23 |
| 1440 // a=sctp-port:<port> |
| 1441 InitAttrLine(kAttributeSctpPort, &os); |
| 1442 os << kSdpDelimiterColon << sctp_port; |
| 1443 // TODO(zstein): emit max-message-size here |
| 1444 } |
| 1427 AddLine(os.str(), message); | 1445 AddLine(os.str(), message); |
| 1428 } | 1446 } |
| 1429 | 1447 |
| 1430 // If unified_plan_sdp is true, will use "a=msid". | 1448 // If unified_plan_sdp is true, will use "a=msid". |
| 1431 void BuildRtpContentAttributes(const MediaContentDescription* media_desc, | 1449 void BuildRtpContentAttributes(const MediaContentDescription* media_desc, |
| 1432 const MediaType media_type, | 1450 const MediaType media_type, |
| 1433 bool unified_plan_sdp, | 1451 bool unified_plan_sdp, |
| 1434 std::string* message) { | 1452 std::string* message) { |
| 1435 std::ostringstream os; | 1453 std::ostringstream os; |
| 1436 // RFC 5285 | 1454 // RFC 5285 |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 | 2302 |
| 2285 // Zero or more media descriptions | 2303 // Zero or more media descriptions |
| 2286 // RFC 4566 | 2304 // RFC 4566 |
| 2287 // m=<media> <port> <proto> <fmt> | 2305 // m=<media> <port> <proto> <fmt> |
| 2288 while (GetLineWithType(message, pos, &line, kLineTypeMedia)) { | 2306 while (GetLineWithType(message, pos, &line, kLineTypeMedia)) { |
| 2289 ++mline_index; | 2307 ++mline_index; |
| 2290 | 2308 |
| 2291 std::vector<std::string> fields; | 2309 std::vector<std::string> fields; |
| 2292 rtc::split(line.substr(kLinePrefixLength), | 2310 rtc::split(line.substr(kLinePrefixLength), |
| 2293 kSdpDelimiterSpace, &fields); | 2311 kSdpDelimiterSpace, &fields); |
| 2312 |
| 2294 const size_t expected_min_fields = 4; | 2313 const size_t expected_min_fields = 4; |
| 2295 if (fields.size() < expected_min_fields) { | 2314 if (fields.size() < expected_min_fields) { |
| 2296 return ParseFailedExpectMinFieldNum(line, expected_min_fields, error); | 2315 return ParseFailedExpectMinFieldNum(line, expected_min_fields, error); |
| 2297 } | 2316 } |
| 2298 bool port_rejected = false; | 2317 bool port_rejected = false; |
| 2299 // RFC 3264 | 2318 // RFC 3264 |
| 2300 // To reject an offered stream, the port number in the corresponding stream | 2319 // To reject an offered stream, the port number in the corresponding stream |
| 2301 // in the answer MUST be set to zero. | 2320 // in the answer MUST be set to zero. |
| 2302 if (fields[1] == kMediaPortRejected) { | 2321 if (fields[1] == kMediaPortRejected) { |
| 2303 port_rejected = true; | 2322 port_rejected = true; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2344 payload_types, pos, &content_name, &bundle_only, &transport, | 2363 payload_types, pos, &content_name, &bundle_only, &transport, |
| 2345 candidates, error)); | 2364 candidates, error)); |
| 2346 } else if (HasAttribute(line, kMediaTypeData)) { | 2365 } else if (HasAttribute(line, kMediaTypeData)) { |
| 2347 DataContentDescription* data_desc = | 2366 DataContentDescription* data_desc = |
| 2348 ParseContentDescription<DataContentDescription>( | 2367 ParseContentDescription<DataContentDescription>( |
| 2349 message, cricket::MEDIA_TYPE_DATA, mline_index, protocol, | 2368 message, cricket::MEDIA_TYPE_DATA, mline_index, protocol, |
| 2350 payload_types, pos, &content_name, &bundle_only, &transport, | 2369 payload_types, pos, &content_name, &bundle_only, &transport, |
| 2351 candidates, error); | 2370 candidates, error); |
| 2352 content.reset(data_desc); | 2371 content.reset(data_desc); |
| 2353 | 2372 |
| 2354 int p; | 2373 if (data_desc && IsDtlsSctp(protocol)) { |
| 2355 if (data_desc && IsDtlsSctp(protocol) && rtc::FromString(fields[3], &p)) { | 2374 int p; |
| 2356 if (!AddSctpDataCodec(data_desc, p)) | 2375 if (rtc::FromString(fields[3], &p)) { |
| 2357 return false; | 2376 if (!AddSctpDataCodec(data_desc, p)) { |
| 2377 return false; |
| 2378 } |
| 2379 } else if (fields[3] == kDefaultSctpmapProtocol) { |
| 2380 data_desc->set_use_sctpmap(false); |
| 2381 } |
| 2358 } | 2382 } |
| 2359 } else { | 2383 } else { |
| 2360 LOG(LS_WARNING) << "Unsupported media type: " << line; | 2384 LOG(LS_WARNING) << "Unsupported media type: " << line; |
| 2361 continue; | 2385 continue; |
| 2362 } | 2386 } |
| 2363 if (!content.get()) { | 2387 if (!content.get()) { |
| 2364 // ParseContentDescription returns NULL if failed. | 2388 // ParseContentDescription returns NULL if failed. |
| 2365 return false; | 2389 return false; |
| 2366 } | 2390 } |
| 2367 | 2391 |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3212 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( | 3236 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( |
| 3213 media_desc, payload_type, feedback_param); | 3237 media_desc, payload_type, feedback_param); |
| 3214 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 3238 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
| 3215 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( | 3239 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( |
| 3216 media_desc, payload_type, feedback_param); | 3240 media_desc, payload_type, feedback_param); |
| 3217 } | 3241 } |
| 3218 return true; | 3242 return true; |
| 3219 } | 3243 } |
| 3220 | 3244 |
| 3221 } // namespace webrtc | 3245 } // namespace webrtc |
| OLD | NEW |