Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: talk/app/webrtc/peerconnection.cc

Issue 1469833006: Fixing issue with default stream upon setting 2nd remote description. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/app/webrtc/peerconnection.h ('k') | talk/app/webrtc/peerconnectioninterface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 // If setting the description decided our SSL role, allocate any necessary 1081 // If setting the description decided our SSL role, allocate any necessary
1082 // SCTP sids. 1082 // SCTP sids.
1083 rtc::SSLRole role; 1083 rtc::SSLRole role;
1084 if (session_->data_channel_type() == cricket::DCT_SCTP && 1084 if (session_->data_channel_type() == cricket::DCT_SCTP &&
1085 session_->GetSslRole(&role)) { 1085 session_->GetSslRole(&role)) {
1086 AllocateSctpSids(role); 1086 AllocateSctpSids(role);
1087 } 1087 }
1088 1088
1089 const cricket::SessionDescription* remote_desc = desc->description(); 1089 const cricket::SessionDescription* remote_desc = desc->description();
1090 1090
1091 remote_info_.msid_supported |= remote_desc->msid_supported();
1092
1091 // We wait to signal new streams until we finish processing the description, 1093 // We wait to signal new streams until we finish processing the description,
1092 // since only at that point will new streams have all their tracks. 1094 // since only at that point will new streams have all their tracks.
1093 rtc::scoped_refptr<StreamCollection> new_streams(StreamCollection::Create()); 1095 rtc::scoped_refptr<StreamCollection> new_streams(StreamCollection::Create());
1094 1096
1095 // Find all audio rtp streams and create corresponding remote AudioTracks 1097 // Find all audio rtp streams and create corresponding remote AudioTracks
1096 // and MediaStreams. 1098 // and MediaStreams.
1097 const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); 1099 const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc);
1098 if (audio_content) { 1100 if (audio_content) {
1099 if (audio_content->rejected) { 1101 if (audio_content->rejected) {
1100 RemoveTracks(cricket::MEDIA_TYPE_AUDIO); 1102 RemoveTracks(cricket::MEDIA_TYPE_AUDIO);
1103 remote_info_.default_audio_track_needed = false;
1101 } else { 1104 } else {
1102 const cricket::AudioContentDescription* desc = 1105 const cricket::AudioContentDescription* desc =
1103 static_cast<const cricket::AudioContentDescription*>( 1106 static_cast<const cricket::AudioContentDescription*>(
1104 audio_content->description); 1107 audio_content->description);
1105 UpdateRemoteStreamsList(GetActiveStreams(desc), desc->type(), 1108 UpdateRemoteStreamsList(GetActiveStreams(desc), desc->type(),
1106 new_streams); 1109 new_streams);
1107 remote_info_.default_audio_track_needed = 1110 remote_info_.default_audio_track_needed =
1108 !remote_desc->msid_supported() && desc->streams().empty() && 1111 !remote_desc->msid_supported() && desc->streams().empty() &&
1109 MediaContentDirectionHasSend(desc->direction()); 1112 MediaContentDirectionHasSend(desc->direction());
1110 } 1113 }
1111 } 1114 }
1112 1115
1113 // Find all video rtp streams and create corresponding remote VideoTracks 1116 // Find all video rtp streams and create corresponding remote VideoTracks
1114 // and MediaStreams. 1117 // and MediaStreams.
1115 const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); 1118 const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc);
1116 if (video_content) { 1119 if (video_content) {
1117 if (video_content->rejected) { 1120 if (video_content->rejected) {
1118 RemoveTracks(cricket::MEDIA_TYPE_VIDEO); 1121 RemoveTracks(cricket::MEDIA_TYPE_VIDEO);
1122 remote_info_.default_video_track_needed = false;
1119 } else { 1123 } else {
1120 const cricket::VideoContentDescription* desc = 1124 const cricket::VideoContentDescription* desc =
1121 static_cast<const cricket::VideoContentDescription*>( 1125 static_cast<const cricket::VideoContentDescription*>(
1122 video_content->description); 1126 video_content->description);
1123 UpdateRemoteStreamsList(GetActiveStreams(desc), desc->type(), 1127 UpdateRemoteStreamsList(GetActiveStreams(desc), desc->type(),
1124 new_streams); 1128 new_streams);
1125 remote_info_.default_video_track_needed = 1129 remote_info_.default_video_track_needed =
1126 !remote_desc->msid_supported() && desc->streams().empty() && 1130 !remote_desc->msid_supported() && desc->streams().empty() &&
1127 MediaContentDirectionHasSend(desc->direction()); 1131 MediaContentDirectionHasSend(desc->direction());
1128 } 1132 }
(...skipping 11 matching lines...) Expand all
1140 } 1144 }
1141 } 1145 }
1142 1146
1143 // Iterate new_streams and notify the observer about new MediaStreams. 1147 // Iterate new_streams and notify the observer about new MediaStreams.
1144 for (size_t i = 0; i < new_streams->count(); ++i) { 1148 for (size_t i = 0; i < new_streams->count(); ++i) {
1145 MediaStreamInterface* new_stream = new_streams->at(i); 1149 MediaStreamInterface* new_stream = new_streams->at(i);
1146 stats_->AddStream(new_stream); 1150 stats_->AddStream(new_stream);
1147 observer_->OnAddStream(new_stream); 1151 observer_->OnAddStream(new_stream);
1148 } 1152 }
1149 1153
1150 // Find removed MediaStreams. 1154 MaybeRemoveDefaultTracks();
1151 if (remote_info_.IsDefaultMediaStreamNeeded() && 1155 UpdateEndedRemoteMediaStreams();
1152 remote_streams_->find(kDefaultStreamLabel) != nullptr) {
1153 // The default media stream already exists. No need to do anything.
1154 } else {
1155 UpdateEndedRemoteMediaStreams();
1156 remote_info_.msid_supported |= remote_streams_->count() > 0;
1157 }
1158 MaybeCreateDefaultStream(); 1156 MaybeCreateDefaultStream();
1159 1157
1160 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); 1158 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer);
1161 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); 1159 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg);
1162 } 1160 }
1163 1161
1164 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { 1162 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) {
1165 if (port_allocator_) { 1163 if (port_allocator_) {
1166 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns; 1164 std::vector<PortAllocatorFactoryInterface::StunConfiguration> stuns;
1167 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns; 1165 std::vector<PortAllocatorFactoryInterface::TurnConfiguration> turns;
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 nullptr); 1494 nullptr);
1497 } 1495 }
1498 1496
1499 void PeerConnection::UpdateRemoteStreamsList( 1497 void PeerConnection::UpdateRemoteStreamsList(
1500 const cricket::StreamParamsVec& streams, 1498 const cricket::StreamParamsVec& streams,
1501 cricket::MediaType media_type, 1499 cricket::MediaType media_type,
1502 StreamCollection* new_streams) { 1500 StreamCollection* new_streams) {
1503 TrackInfos* current_tracks = GetRemoteTracks(media_type); 1501 TrackInfos* current_tracks = GetRemoteTracks(media_type);
1504 1502
1505 // Find removed tracks. I.e., tracks where the track id or ssrc don't match 1503 // Find removed tracks. I.e., tracks where the track id or ssrc don't match
1506 // the 1504 // the new StreamParam.
1507 // new StreamParam.
1508 auto track_it = current_tracks->begin(); 1505 auto track_it = current_tracks->begin();
1509 while (track_it != current_tracks->end()) { 1506 while (track_it != current_tracks->end()) {
1510 const TrackInfo& info = *track_it; 1507 const TrackInfo& info = *track_it;
1511 const cricket::StreamParams* params = 1508 const cricket::StreamParams* params =
1512 cricket::GetStreamBySsrc(streams, info.ssrc); 1509 cricket::GetStreamBySsrc(streams, info.ssrc);
1513 if (!params || params->id != info.track_id) { 1510 if (info.stream_label != kDefaultStreamLabel &&
pthatcher1 2015/12/02 22:05:53 Would it be cleaner to put this inside of UpdateRe
1511 (!params || params->id != info.track_id)) {
1514 OnRemoteTrackRemoved(info.stream_label, info.track_id, media_type); 1512 OnRemoteTrackRemoved(info.stream_label, info.track_id, media_type);
1515 track_it = current_tracks->erase(track_it); 1513 track_it = current_tracks->erase(track_it);
1516 } else { 1514 } else {
1517 ++track_it; 1515 ++track_it;
1518 } 1516 }
1519 } 1517 }
1520 1518
1521 // Find new and active tracks. 1519 // Find new and active tracks.
1522 for (const cricket::StreamParams& params : streams) { 1520 for (const cricket::StreamParams& params : streams) {
1523 // The sync_label is the MediaStream label and the |stream.id| is the 1521 // The sync_label is the MediaStream label and the |stream.id| is the
1524 // track id. 1522 // track id.
1525 const std::string& stream_label = params.sync_label; 1523 const std::string& stream_label = params.sync_label;
1526 const std::string& track_id = params.id; 1524 const std::string& track_id = params.id;
1527 uint32_t ssrc = params.first_ssrc(); 1525 uint32_t ssrc = params.first_ssrc();
1528 1526
1529 rtc::scoped_refptr<MediaStreamInterface> stream = 1527 rtc::scoped_refptr<MediaStreamInterface> stream =
1530 remote_streams_->find(stream_label); 1528 remote_streams_->find(stream_label);
1531 if (!stream) { 1529 if (!stream) {
1532 // This is a new MediaStream. Create a new remote MediaStream. 1530 // This is a new MediaStream. Create a new remote MediaStream.
1533 stream = remote_stream_factory_->CreateMediaStream(stream_label); 1531 stream = remote_stream_factory_->CreateMediaStream(stream_label);
1534 remote_streams_->AddStream(stream); 1532 remote_streams_->AddStream(stream);
1535 new_streams->AddStream(stream); 1533 new_streams->AddStream(stream);
1534 // Just in case the peer supports MSID, but doesn't indicate so with
1535 // "a=msid-semantic"...
1536 remote_info_.msid_supported = true;
1536 } 1537 }
1537 1538
1538 const TrackInfo* track_info = 1539 const TrackInfo* track_info =
1539 FindTrackInfo(*current_tracks, stream_label, track_id); 1540 FindTrackInfo(*current_tracks, stream_label, track_id);
1540 if (!track_info) { 1541 if (!track_info) {
1541 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc)); 1542 current_tracks->push_back(TrackInfo(stream_label, track_id, ssrc));
1542 OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type); 1543 OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type);
1543 } 1544 }
1544 } 1545 }
1545 } 1546 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 streams_to_remove.push_back(stream); 1598 streams_to_remove.push_back(stream);
1598 } 1599 }
1599 } 1600 }
1600 1601
1601 for (const auto& stream : streams_to_remove) { 1602 for (const auto& stream : streams_to_remove) {
1602 remote_streams_->RemoveStream(stream); 1603 remote_streams_->RemoveStream(stream);
1603 observer_->OnRemoveStream(stream); 1604 observer_->OnRemoveStream(stream);
1604 } 1605 }
1605 } 1606 }
1606 1607
1608 void PeerConnection::MaybeRemoveDefaultTracks() {
1609 rtc::scoped_refptr<MediaStreamInterface> default_remote_stream =
1610 remote_streams_->find(kDefaultStreamLabel);
1611 if (!default_remote_stream) {
1612 return;
1613 }
1614
1615 if ((!remote_info_.IsDefaultMediaStreamNeeded() ||
1616 !remote_info_.default_audio_track_needed) &&
1617 default_remote_stream->GetAudioTracks().size() > 0) {
1618 auto it =
1619 std::find(remote_audio_tracks_.begin(), remote_audio_tracks_.end(),
1620 TrackInfo(kDefaultStreamLabel, kDefaultAudioTrackLabel, 0));
1621 if (it != remote_audio_tracks_.end()) {
1622 OnRemoteTrackRemoved(kDefaultStreamLabel, kDefaultAudioTrackLabel,
1623 cricket::MEDIA_TYPE_AUDIO);
1624 remote_audio_tracks_.erase(it);
1625 }
1626 }
1627
1628 if ((!remote_info_.IsDefaultMediaStreamNeeded() ||
1629 !remote_info_.default_video_track_needed) &&
1630 default_remote_stream->GetVideoTracks().size() > 0) {
1631 auto it =
1632 std::find(remote_video_tracks_.begin(), remote_video_tracks_.end(),
1633 TrackInfo(kDefaultStreamLabel, kDefaultVideoTrackLabel, 0));
1634 if (it != remote_video_tracks_.end()) {
1635 OnRemoteTrackRemoved(kDefaultStreamLabel, kDefaultVideoTrackLabel,
1636 cricket::MEDIA_TYPE_VIDEO);
1637 remote_video_tracks_.erase(it);
1638 }
1639 }
1640 }
1641
1607 void PeerConnection::MaybeCreateDefaultStream() { 1642 void PeerConnection::MaybeCreateDefaultStream() {
1608 if (!remote_info_.IsDefaultMediaStreamNeeded()) { 1643 if (!remote_info_.IsDefaultMediaStreamNeeded()) {
1609 return; 1644 return;
1610 } 1645 }
1611 1646
1612 bool default_created = false; 1647 bool default_created = false;
1613 1648
1614 rtc::scoped_refptr<MediaStreamInterface> default_remote_stream = 1649 rtc::scoped_refptr<MediaStreamInterface> default_remote_stream =
1615 remote_streams_->find(kDefaultStreamLabel); 1650 remote_streams_->find(kDefaultStreamLabel);
1616 if (default_remote_stream == nullptr) { 1651 if (default_remote_stream == nullptr) {
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2029 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2064 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2030 for (const auto& channel : sctp_data_channels_) { 2065 for (const auto& channel : sctp_data_channels_) {
2031 if (channel->id() == sid) { 2066 if (channel->id() == sid) {
2032 return channel; 2067 return channel;
2033 } 2068 }
2034 } 2069 }
2035 return nullptr; 2070 return nullptr;
2036 } 2071 }
2037 2072
2038 } // namespace webrtc 2073 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/peerconnection.h ('k') | talk/app/webrtc/peerconnectioninterface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698