Chromium Code Reviews| Index: talk/app/webrtc/peerconnection.cc |
| diff --git a/talk/app/webrtc/peerconnection.cc b/talk/app/webrtc/peerconnection.cc |
| index caa892d00b9b04802c15908b04f97bd4ddf3cfb1..6fbafc718efb3f3ae1da9d29c105cc96dd66d586 100644 |
| --- a/talk/app/webrtc/peerconnection.cc |
| +++ b/talk/app/webrtc/peerconnection.cc |
| @@ -1087,6 +1087,26 @@ void PeerConnection::SetRemoteDescription( |
| } |
| const cricket::SessionDescription* remote_desc = desc->description(); |
| + const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); |
| + const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); |
|
pthatcher1
2015/12/03 20:07:39
I think you can use
const cricket::AudioContentD
Taylor Brandstetter
2015/12/04 22:04:54
I still need the ContentInfo pointers to tell if t
|
| + |
| + remote_peer_msid_supported_ |= remote_desc->msid_supported(); |
| + // Just in case the peer supports MSID, but doesn't indicate so with |
| + // "a=msid-semantic"... |
| + if (audio_content && |
| + !static_cast<const cricket::AudioContentDescription*>( |
| + audio_content->description) |
| + ->streams() |
| + .empty()) { |
| + remote_peer_msid_supported_ = true; |
| + } |
| + if (video_content && |
| + !static_cast<const cricket::VideoContentDescription*>( |
| + video_content->description) |
| + ->streams() |
| + .empty()) { |
| + remote_peer_msid_supported_ = true; |
| + } |
|
pthatcher1
2015/12/03 20:07:40
I think it could be:
auto audio = GetFirstAudioCo
Taylor Brandstetter
2015/12/04 22:04:54
Done.
|
| // We wait to signal new streams until we finish processing the description, |
| // since only at that point will new streams have all their tracks. |
| @@ -1094,7 +1114,6 @@ void PeerConnection::SetRemoteDescription( |
| // Find all audio rtp streams and create corresponding remote AudioTracks |
| // and MediaStreams. |
| - const cricket::ContentInfo* audio_content = GetFirstAudioContent(remote_desc); |
| if (audio_content) { |
| if (audio_content->rejected) { |
| RemoveTracks(cricket::MEDIA_TYPE_AUDIO); |
| @@ -1102,17 +1121,17 @@ void PeerConnection::SetRemoteDescription( |
| const cricket::AudioContentDescription* desc = |
| static_cast<const cricket::AudioContentDescription*>( |
| audio_content->description); |
|
pthatcher1
2015/12/03 20:07:40
This line (or 3) could go away if you use the func
Taylor Brandstetter
2015/12/04 22:04:54
Done.
|
| - UpdateRemoteStreamsList(GetActiveStreams(desc), desc->type(), |
| - new_streams); |
| - remote_info_.default_audio_track_needed = |
| - !remote_desc->msid_supported() && desc->streams().empty() && |
| + bool default_audio_track_needed = |
| + !remote_peer_msid_supported_ && desc->streams().empty() && |
| MediaContentDirectionHasSend(desc->direction()); |
| + UpdateRemoteStreamsList(GetActiveStreams(desc), |
| + default_audio_track_needed, desc->type(), |
| + new_streams); |
| } |
| } |
| // Find all video rtp streams and create corresponding remote VideoTracks |
| // and MediaStreams. |
| - const cricket::ContentInfo* video_content = GetFirstVideoContent(remote_desc); |
| if (video_content) { |
| if (video_content->rejected) { |
| RemoveTracks(cricket::MEDIA_TYPE_VIDEO); |
| @@ -1120,11 +1139,12 @@ void PeerConnection::SetRemoteDescription( |
| const cricket::VideoContentDescription* desc = |
| static_cast<const cricket::VideoContentDescription*>( |
| video_content->description); |
| - UpdateRemoteStreamsList(GetActiveStreams(desc), desc->type(), |
| - new_streams); |
| - remote_info_.default_video_track_needed = |
| - !remote_desc->msid_supported() && desc->streams().empty() && |
| + bool default_video_track_needed = |
| + !remote_peer_msid_supported_ && desc->streams().empty() && |
| MediaContentDirectionHasSend(desc->direction()); |
| + UpdateRemoteStreamsList(GetActiveStreams(desc), |
| + default_video_track_needed, desc->type(), |
| + new_streams); |
| } |
| } |
| @@ -1147,15 +1167,7 @@ void PeerConnection::SetRemoteDescription( |
| observer_->OnAddStream(new_stream); |
| } |
| - // Find removed MediaStreams. |
| - if (remote_info_.IsDefaultMediaStreamNeeded() && |
| - remote_streams_->find(kDefaultStreamLabel) != nullptr) { |
| - // The default media stream already exists. No need to do anything. |
| - } else { |
| - UpdateEndedRemoteMediaStreams(); |
| - remote_info_.msid_supported |= remote_streams_->count() > 0; |
| - } |
| - MaybeCreateDefaultStream(); |
| + UpdateEndedRemoteMediaStreams(); |
| SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); |
| signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); |
| @@ -1492,25 +1504,30 @@ bool PeerConnection::GetOptionsForAnswer( |
| void PeerConnection::RemoveTracks(cricket::MediaType media_type) { |
| UpdateLocalTracks(std::vector<cricket::StreamParams>(), media_type); |
| - UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), media_type, |
| - nullptr); |
| + UpdateRemoteStreamsList(std::vector<cricket::StreamParams>(), false, |
| + media_type, nullptr); |
| } |
| void PeerConnection::UpdateRemoteStreamsList( |
| const cricket::StreamParamsVec& streams, |
| + bool default_track_needed, |
| cricket::MediaType media_type, |
| StreamCollection* new_streams) { |
| TrackInfos* current_tracks = GetRemoteTracks(media_type); |
| // Find removed tracks. I.e., tracks where the track id or ssrc don't match |
| - // the |
| - // new StreamParam. |
| + // the new StreamParam. |
| auto track_it = current_tracks->begin(); |
| while (track_it != current_tracks->end()) { |
| const TrackInfo& info = *track_it; |
| const cricket::StreamParams* params = |
| cricket::GetStreamBySsrc(streams, info.ssrc); |
| if (!params || params->id != info.track_id) { |
| + // If this is a default track, and we still need it, don't remove it. |
| + if (info.stream_label == kDefaultStreamLabel && default_track_needed) { |
| + ++track_it; |
| + continue; |
| + } |
| OnRemoteTrackRemoved(info.stream_label, info.track_id, media_type); |
| track_it = current_tracks->erase(track_it); |
| } else { |
| @@ -1542,6 +1559,27 @@ void PeerConnection::UpdateRemoteStreamsList( |
| OnRemoteTrackSeen(stream_label, track_id, ssrc, media_type); |
| } |
| } |
| + |
| + // Add default track if necessary. |
| + if (default_track_needed) { |
| + rtc::scoped_refptr<MediaStreamInterface> stream = |
| + remote_streams_->find(kDefaultStreamLabel); |
|
pthatcher1
2015/12/03 20:07:40
A better name for that variable might be "default_
Taylor Brandstetter
2015/12/04 22:04:54
Done.
|
| + if (!stream) { |
| + // Create the new default MediaStream. |
| + stream = remote_stream_factory_->CreateMediaStream(kDefaultStreamLabel); |
| + remote_streams_->AddStream(stream); |
| + new_streams->AddStream(stream); |
| + } |
| + std::string track_id = (media_type == cricket::MEDIA_TYPE_AUDIO) |
| + ? kDefaultAudioTrackLabel |
| + : kDefaultVideoTrackLabel; |
|
pthatcher1
2015/12/03 20:07:40
And that default_track_id
Taylor Brandstetter
2015/12/04 22:04:54
Done.
|
| + const TrackInfo* track_info = |
| + FindTrackInfo(*current_tracks, kDefaultStreamLabel, track_id); |
|
pthatcher1
2015/12/03 20:07:40
And that default_track
Taylor Brandstetter
2015/12/04 22:04:54
Done.
|
| + if (!track_info) { |
| + current_tracks->push_back(TrackInfo(kDefaultStreamLabel, track_id, 0)); |
| + OnRemoteTrackSeen(kDefaultStreamLabel, track_id, 0, media_type); |
| + } |
| + } |
| } |
| void PeerConnection::OnRemoteTrackSeen(const std::string& stream_label, |
| @@ -1604,41 +1642,6 @@ void PeerConnection::UpdateEndedRemoteMediaStreams() { |
| } |
| } |
| -void PeerConnection::MaybeCreateDefaultStream() { |
| - if (!remote_info_.IsDefaultMediaStreamNeeded()) { |
| - return; |
| - } |
| - |
| - bool default_created = false; |
| - |
| - rtc::scoped_refptr<MediaStreamInterface> default_remote_stream = |
| - remote_streams_->find(kDefaultStreamLabel); |
| - if (default_remote_stream == nullptr) { |
| - default_created = true; |
| - default_remote_stream = |
| - remote_stream_factory_->CreateMediaStream(kDefaultStreamLabel); |
| - remote_streams_->AddStream(default_remote_stream); |
| - } |
| - if (remote_info_.default_audio_track_needed && |
| - default_remote_stream->GetAudioTracks().size() == 0) { |
| - remote_audio_tracks_.push_back( |
| - TrackInfo(kDefaultStreamLabel, kDefaultAudioTrackLabel, 0)); |
| - OnRemoteTrackSeen(kDefaultStreamLabel, kDefaultAudioTrackLabel, 0, |
| - cricket::MEDIA_TYPE_AUDIO); |
| - } |
| - if (remote_info_.default_video_track_needed && |
| - default_remote_stream->GetVideoTracks().size() == 0) { |
| - remote_video_tracks_.push_back( |
| - TrackInfo(kDefaultStreamLabel, kDefaultVideoTrackLabel, 0)); |
| - OnRemoteTrackSeen(kDefaultStreamLabel, kDefaultVideoTrackLabel, 0, |
| - cricket::MEDIA_TYPE_VIDEO); |
| - } |
| - if (default_created) { |
| - stats_->AddStream(default_remote_stream); |
| - observer_->OnAddStream(default_remote_stream); |
| - } |
| -} |
| - |
| void PeerConnection::EndRemoteTracks(cricket::MediaType media_type) { |
| TrackInfos* current_tracks = GetRemoteTracks(media_type); |
| for (TrackInfos::iterator track_it = current_tracks->begin(); |