OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 446 |
447 bool ConvertRtcOptionsForOffer( | 447 bool ConvertRtcOptionsForOffer( |
448 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 448 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
449 cricket::MediaSessionOptions* session_options) { | 449 cricket::MediaSessionOptions* session_options) { |
450 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; | 450 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
451 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || | 451 if (!IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_audio) || |
452 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { | 452 !IsValidOfferToReceiveMedia(rtc_options.offer_to_receive_video)) { |
453 return false; | 453 return false; |
454 } | 454 } |
455 | 455 |
456 // According to the spec, offer to receive audio/video if the constraint is | 456 if (rtc_options.offer_to_receive_audio != RTCOfferAnswerOptions::kUndefined) { |
457 // not set and there are send streams. | |
458 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { | |
459 session_options->recv_audio = | |
460 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO); | |
461 } else { | |
462 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); | 457 session_options->recv_audio = (rtc_options.offer_to_receive_audio > 0); |
463 } | 458 } |
464 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { | 459 if (rtc_options.offer_to_receive_video != RTCOfferAnswerOptions::kUndefined) { |
465 session_options->recv_video = | |
466 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO); | |
467 } else { | |
468 session_options->recv_video = (rtc_options.offer_to_receive_video > 0); | 460 session_options->recv_video = (rtc_options.offer_to_receive_video > 0); |
469 } | 461 } |
470 | 462 |
471 session_options->vad_enabled = rtc_options.voice_activity_detection; | 463 session_options->vad_enabled = rtc_options.voice_activity_detection; |
472 session_options->transport_options.ice_restart = rtc_options.ice_restart; | 464 session_options->transport_options.ice_restart = rtc_options.ice_restart; |
473 session_options->bundle_enabled = | 465 session_options->bundle_enabled = rtc_options.use_rtp_mux; |
474 rtc_options.use_rtp_mux && | |
475 (session_options->has_audio() || session_options->has_video() || | |
476 session_options->has_data()); | |
477 | 466 |
478 return true; | 467 return true; |
479 } | 468 } |
480 | 469 |
481 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, | 470 bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
482 cricket::MediaSessionOptions* session_options) { | 471 cricket::MediaSessionOptions* session_options) { |
483 bool value = false; | 472 bool value = false; |
484 size_t mandatory_constraints_satisfied = 0; | 473 size_t mandatory_constraints_satisfied = 0; |
485 | 474 |
486 // kOfferToReceiveAudio defaults to true according to spec. | 475 // kOfferToReceiveAudio defaults to true according to spec. |
(...skipping 21 matching lines...) Expand all Loading... |
508 session_options->vad_enabled = value; | 497 session_options->vad_enabled = value; |
509 } | 498 } |
510 | 499 |
511 if (FindConstraint(constraints, MediaConstraintsInterface::kUseRtpMux, &value, | 500 if (FindConstraint(constraints, MediaConstraintsInterface::kUseRtpMux, &value, |
512 &mandatory_constraints_satisfied)) { | 501 &mandatory_constraints_satisfied)) { |
513 session_options->bundle_enabled = value; | 502 session_options->bundle_enabled = value; |
514 } else { | 503 } else { |
515 // kUseRtpMux defaults to true according to spec. | 504 // kUseRtpMux defaults to true according to spec. |
516 session_options->bundle_enabled = true; | 505 session_options->bundle_enabled = true; |
517 } | 506 } |
518 session_options->bundle_enabled = | |
519 session_options->bundle_enabled && | |
520 (session_options->has_audio() || session_options->has_video() || | |
521 session_options->has_data()); | |
522 | 507 |
523 if (FindConstraint(constraints, MediaConstraintsInterface::kIceRestart, | 508 if (FindConstraint(constraints, MediaConstraintsInterface::kIceRestart, |
524 &value, &mandatory_constraints_satisfied)) { | 509 &value, &mandatory_constraints_satisfied)) { |
525 session_options->transport_options.ice_restart = value; | 510 session_options->transport_options.ice_restart = value; |
526 } else { | 511 } else { |
527 // kIceRestart defaults to false according to spec. | 512 // kIceRestart defaults to false according to spec. |
528 session_options->transport_options.ice_restart = false; | 513 session_options->transport_options.ice_restart = false; |
529 } | 514 } |
530 | 515 |
531 if (!constraints) { | 516 if (!constraints) { |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 | 1011 |
1027 // Find all audio rtp streams and create corresponding remote AudioTracks | 1012 // Find all audio rtp streams and create corresponding remote AudioTracks |
1028 // and MediaStreams. | 1013 // and MediaStreams. |
1029 const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); | 1014 const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); |
1030 if (audio_content) { | 1015 if (audio_content) { |
1031 const cricket::AudioContentDescription* desc = | 1016 const cricket::AudioContentDescription* desc = |
1032 static_cast<const cricket::AudioContentDescription*>( | 1017 static_cast<const cricket::AudioContentDescription*>( |
1033 audio_content->description); | 1018 audio_content->description); |
1034 UpdateRemoteStreamsList(desc->streams(), desc->type(), new_streams); | 1019 UpdateRemoteStreamsList(desc->streams(), desc->type(), new_streams); |
1035 remote_info_.default_audio_track_needed = | 1020 remote_info_.default_audio_track_needed = |
1036 MediaContentDirectionHasSend(desc->direction()) && | 1021 !remote_desc->msid_supported() && desc->streams().empty() && |
1037 desc->streams().empty(); | 1022 MediaContentDirectionHasSend(desc->direction()); |
1038 } | 1023 } |
1039 | 1024 |
1040 // Find all video rtp streams and create corresponding remote VideoTracks | 1025 // Find all video rtp streams and create corresponding remote VideoTracks |
1041 // and MediaStreams. | 1026 // and MediaStreams. |
1042 const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); | 1027 const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); |
1043 if (video_content) { | 1028 if (video_content) { |
1044 const cricket::VideoContentDescription* desc = | 1029 const cricket::VideoContentDescription* desc = |
1045 static_cast<const cricket::VideoContentDescription*>( | 1030 static_cast<const cricket::VideoContentDescription*>( |
1046 video_content->description); | 1031 video_content->description); |
1047 UpdateRemoteStreamsList(desc->streams(), desc->type(), new_streams); | 1032 UpdateRemoteStreamsList(desc->streams(), desc->type(), new_streams); |
1048 remote_info_.default_video_track_needed = | 1033 remote_info_.default_video_track_needed = |
1049 MediaContentDirectionHasSend(desc->direction()) && | 1034 !remote_desc->msid_supported() && desc->streams().empty() && |
1050 desc->streams().empty(); | 1035 MediaContentDirectionHasSend(desc->direction()); |
1051 } | 1036 } |
1052 | 1037 |
1053 // Update the DataChannels with the information from the remote peer. | 1038 // Update the DataChannels with the information from the remote peer. |
1054 const cricket::ContentInfo* data_content = GetFirstDataContent(remote_desc); | 1039 const cricket::ContentInfo* data_content = GetFirstDataContent(remote_desc); |
1055 if (data_content) { | 1040 if (data_content) { |
1056 const cricket::DataContentDescription* data_desc = | 1041 const cricket::DataContentDescription* data_desc = |
1057 static_cast<const cricket::DataContentDescription*>( | 1042 static_cast<const cricket::DataContentDescription*>( |
1058 data_content->description); | 1043 data_content->description); |
1059 if (rtc::starts_with(data_desc->protocol().data(), | 1044 if (rtc::starts_with(data_desc->protocol().data(), |
1060 cricket::kMediaProtocolRtpPrefix)) { | 1045 cricket::kMediaProtocolRtpPrefix)) { |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 CreateSessionDescriptionObserver* observer, | 1364 CreateSessionDescriptionObserver* observer, |
1380 const std::string& error) { | 1365 const std::string& error) { |
1381 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); | 1366 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
1382 msg->error = error; | 1367 msg->error = error; |
1383 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); | 1368 signaling_thread()->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); |
1384 } | 1369 } |
1385 | 1370 |
1386 bool PeerConnection::GetOptionsForOffer( | 1371 bool PeerConnection::GetOptionsForOffer( |
1387 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 1372 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
1388 cricket::MediaSessionOptions* session_options) { | 1373 cricket::MediaSessionOptions* session_options) { |
1389 SetStreams(session_options, local_streams_, rtp_data_channels_); | |
1390 | |
1391 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { | 1374 if (!ConvertRtcOptionsForOffer(rtc_options, session_options)) { |
1392 return false; | 1375 return false; |
1393 } | 1376 } |
1394 | 1377 |
| 1378 SetStreams(session_options, local_streams_, rtp_data_channels_); |
| 1379 // Offer to receive audio/video if the constraint is not set and there are |
| 1380 // send streams, or we're currently receiving. |
| 1381 if (rtc_options.offer_to_receive_audio == RTCOfferAnswerOptions::kUndefined) { |
| 1382 session_options->recv_audio = |
| 1383 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO) || |
| 1384 !remote_audio_tracks_.empty(); |
| 1385 } |
| 1386 if (rtc_options.offer_to_receive_video == RTCOfferAnswerOptions::kUndefined) { |
| 1387 session_options->recv_video = |
| 1388 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO) || |
| 1389 !remote_video_tracks_.empty(); |
| 1390 } |
| 1391 session_options->bundle_enabled = |
| 1392 session_options->bundle_enabled && |
| 1393 (session_options->has_audio() || session_options->has_video() || |
| 1394 session_options->has_data()); |
| 1395 |
1395 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { | 1396 if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { |
1396 session_options->data_channel_type = cricket::DCT_SCTP; | 1397 session_options->data_channel_type = cricket::DCT_SCTP; |
1397 } | 1398 } |
1398 return true; | 1399 return true; |
1399 } | 1400 } |
1400 | 1401 |
1401 bool PeerConnection::GetOptionsForAnswer( | 1402 bool PeerConnection::GetOptionsForAnswer( |
1402 const MediaConstraintsInterface* constraints, | 1403 const MediaConstraintsInterface* constraints, |
1403 cricket::MediaSessionOptions* session_options) { | 1404 cricket::MediaSessionOptions* session_options) { |
1404 SetStreams(session_options, local_streams_, rtp_data_channels_); | |
1405 session_options->recv_audio = false; | 1405 session_options->recv_audio = false; |
1406 session_options->recv_video = false; | 1406 session_options->recv_video = false; |
1407 | |
1408 if (!ParseConstraintsForAnswer(constraints, session_options)) { | 1407 if (!ParseConstraintsForAnswer(constraints, session_options)) { |
1409 return false; | 1408 return false; |
1410 } | 1409 } |
1411 | 1410 |
| 1411 SetStreams(session_options, local_streams_, rtp_data_channels_); |
| 1412 session_options->bundle_enabled = |
| 1413 session_options->bundle_enabled && |
| 1414 (session_options->has_audio() || session_options->has_video() || |
| 1415 session_options->has_data()); |
| 1416 |
1412 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 1417 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
1413 // are not signaled in the SDP so does not go through that path and must be | 1418 // are not signaled in the SDP so does not go through that path and must be |
1414 // handled here. | 1419 // handled here. |
1415 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 1420 if (session_->data_channel_type() == cricket::DCT_SCTP) { |
1416 session_options->data_channel_type = cricket::DCT_SCTP; | 1421 session_options->data_channel_type = cricket::DCT_SCTP; |
1417 } | 1422 } |
1418 return true; | 1423 return true; |
1419 } | 1424 } |
1420 | 1425 |
1421 void PeerConnection::UpdateRemoteStreamsList( | 1426 void PeerConnection::UpdateRemoteStreamsList( |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1951 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { | 1956 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { |
1952 for (const auto& channel : sctp_data_channels_) { | 1957 for (const auto& channel : sctp_data_channels_) { |
1953 if (channel->id() == sid) { | 1958 if (channel->id() == sid) { |
1954 return channel; | 1959 return channel; |
1955 } | 1960 } |
1956 } | 1961 } |
1957 return nullptr; | 1962 return nullptr; |
1958 } | 1963 } |
1959 | 1964 |
1960 } // namespace webrtc | 1965 } // namespace webrtc |
OLD | NEW |