Chromium Code Reviews| Index: content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc |
| diff --git a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc |
| index 12601f672a1b7ae19c25cc8f8e04cdd5b03d80c5..091ba63aa07629b2ecdc80d8ea2e1cb60fd04949 100644 |
| --- a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc |
| +++ b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc |
| @@ -11,6 +11,7 @@ |
| #include "content/shell/renderer/test_runner/test_interfaces.h" |
| #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| +#include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
| #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h" |
| @@ -144,7 +145,7 @@ class RemoteDataChannelTask |
| ///////////////////// |
| -MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() { |
| +MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() { |
| } |
| MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( |
| @@ -223,7 +224,9 @@ void MockWebRTCPeerConnectionHandler::setLocalDescription( |
| void MockWebRTCPeerConnectionHandler::setRemoteDescription( |
| const WebRTCVoidRequest& request, |
| const WebRTCSessionDescription& remote_description) { |
| + |
| if (!remote_description.isNull() && remote_description.sdp() == "remote") { |
| + UpdateRemoteStreams(); |
| remote_description_ = remote_description; |
| interfaces_->GetDelegate()->postTask( |
| new RTCVoidRequestTask(this, request, true)); |
| @@ -232,6 +235,84 @@ void MockWebRTCPeerConnectionHandler::setRemoteDescription( |
| new RTCVoidRequestTask(this, request, false)); |
| } |
| +void MockWebRTCPeerConnectionHandler::UpdateRemoteStreams() { |
| + // Find all removed streams. |
| + // Set the readyState of the remote tracks to ended, remove them from the |
| + // stream and notify the client. |
| + StreamMap::iterator removed_it = remote_streams_.begin(); |
| + while(removed_it != remote_streams_.end()) { |
| + if (local_streams_.find(removed_it->first) != local_streams_.end()) { |
| + removed_it++; |
| + continue; |
| + } |
| + |
| + // The stream have been removed. Loop through all tracks and set the |
| + // source as ended and remove them from the stream. |
| + blink::WebMediaStream stream = removed_it->second; |
| + blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; |
| + stream.audioTracks(audio_tracks); |
| + for (size_t i = 0; i < audio_tracks.size(); ++i) { |
| + audio_tracks[i].source().setReadyState( |
| + blink::WebMediaStreamSource::ReadyStateEnded); |
| + stream.removeTrack(audio_tracks[i]); |
| + } |
| + |
| + blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| + stream.videoTracks(video_tracks); |
| + for (size_t i = 0; i < video_tracks.size(); ++i) { |
| + video_tracks[i].source().setReadyState( |
| + blink::WebMediaStreamSource::ReadyStateEnded); |
| + stream.removeTrack(video_tracks[i]); |
| + } |
| + client_->didRemoveRemoteStream(stream); |
| + remote_streams_.erase(removed_it++); |
| + } |
| + |
| + // Find all new streams; |
| + // Create new sources and tracks and notify the client about the new stream. |
| + StreamMap::iterator added_it = local_streams_.begin(); |
| + while(added_it != local_streams_.end()) { |
| + if (remote_streams_.find(added_it->first) != remote_streams_.end()) { |
| + added_it++; |
| + continue; |
| + } |
| + |
| + const blink::WebMediaStream& stream = added_it->second; |
| + |
| + blink::WebVector<blink::WebMediaStreamTrack> local_audio_tracks; |
| + stream.audioTracks(local_audio_tracks); |
| + blink::WebVector<blink::WebMediaStreamTrack> |
| + remote_audio_tracks(local_audio_tracks.size()); |
| + |
| + for (size_t i = 0; i < local_audio_tracks.size(); ++i) { |
| + blink::WebMediaStreamSource webkit_source; |
| + webkit_source.initialize(local_audio_tracks[i].id(), |
| + blink::WebMediaStreamSource::TypeAudio, |
| + local_audio_tracks[i].id()); |
|
hta - Chromium
2014/09/30 09:43:49
Shouldn't you be using the new flags here? this se
perkj_chrome
2014/09/30 18:38:30
Yes, but I would prefer to do that when I change a
|
| + remote_audio_tracks[i].initialize(webkit_source); |
| + } |
| + |
| + blink::WebVector<blink::WebMediaStreamTrack> local_video_tracks; |
| + stream.videoTracks(local_video_tracks); |
| + blink::WebVector<blink::WebMediaStreamTrack> |
| + remote_video_tracks(local_video_tracks.size()); |
| + for (size_t i = 0; i < local_video_tracks.size(); ++i) { |
| + blink::WebMediaStreamSource webkit_source; |
| + webkit_source.initialize(local_video_tracks[i].id(), |
| + blink::WebMediaStreamSource::TypeVideo, |
| + local_audio_tracks[i].id()); |
|
hta - Chromium
2014/09/30 09:43:49
The occurence of "audio" in this line looks strang
perkj_chrome
2014/09/30 18:38:30
Yes, wrong.
|
| + remote_video_tracks[i].initialize(webkit_source); |
| + } |
| + |
| + blink::WebMediaStream new_remote_stream; |
| + new_remote_stream.initialize(remote_audio_tracks, |
| + remote_video_tracks); |
| + remote_streams_[added_it->first] = new_remote_stream; |
| + client_->didAddRemoteStream(new_remote_stream); |
| + ++added_it; |
| + } |
| +} |
| + |
| WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() { |
| return local_description_; |
| } |
| @@ -265,12 +346,15 @@ bool MockWebRTCPeerConnectionHandler::addStream( |
| const WebMediaConstraints& constraints) { |
| ++stream_count_; |
| client_->negotiationNeeded(); |
| + DCHECK(local_streams_.find(stream.id().utf8()) == local_streams_.end()); |
|
hta - Chromium
2014/09/30 09:43:49
This is actually not according to spec. Spec says
perkj_chrome
2014/09/30 18:38:30
ok- this was to help debugging tests. It looks lik
|
| + local_streams_[stream.id().utf8()] = stream; |
| return true; |
| } |
| void MockWebRTCPeerConnectionHandler::removeStream( |
| const WebMediaStream& stream) { |
| --stream_count_; |
| + local_streams_.erase(stream.id().utf8()); |
| client_->negotiationNeeded(); |
| } |