OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/webrtc_connection_to_host.h" | 5 #include "remoting/protocol/webrtc_connection_to_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
| 9 #include "base/strings/string_util.h" |
9 #include "jingle/glue/thread_wrapper.h" | 10 #include "jingle/glue/thread_wrapper.h" |
| 11 #include "remoting/base/constants.h" |
10 #include "remoting/protocol/client_control_dispatcher.h" | 12 #include "remoting/protocol/client_control_dispatcher.h" |
11 #include "remoting/protocol/client_event_dispatcher.h" | 13 #include "remoting/protocol/client_event_dispatcher.h" |
12 #include "remoting/protocol/client_stub.h" | 14 #include "remoting/protocol/client_stub.h" |
13 #include "remoting/protocol/clipboard_stub.h" | 15 #include "remoting/protocol/clipboard_stub.h" |
14 #include "remoting/protocol/message_pipe.h" | 16 #include "remoting/protocol/message_pipe.h" |
15 #include "remoting/protocol/transport_context.h" | 17 #include "remoting/protocol/transport_context.h" |
16 #include "remoting/protocol/video_renderer.h" | 18 #include "remoting/protocol/video_renderer.h" |
17 #include "remoting/protocol/webrtc_transport.h" | 19 #include "remoting/protocol/webrtc_transport.h" |
18 #include "remoting/protocol/webrtc_video_renderer_adapter.h" | 20 #include "remoting/protocol/webrtc_video_renderer_adapter.h" |
19 | 21 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 void WebrtcConnectionToHost::OnWebrtcTransportError(ErrorCode error) { | 116 void WebrtcConnectionToHost::OnWebrtcTransportError(ErrorCode error) { |
115 CloseChannels(); | 117 CloseChannels(); |
116 SetState(FAILED, error); | 118 SetState(FAILED, error); |
117 } | 119 } |
118 | 120 |
119 void WebrtcConnectionToHost::OnWebrtcTransportIncomingDataChannel( | 121 void WebrtcConnectionToHost::OnWebrtcTransportIncomingDataChannel( |
120 const std::string& name, | 122 const std::string& name, |
121 std::unique_ptr<MessagePipe> pipe) { | 123 std::unique_ptr<MessagePipe> pipe) { |
122 if (!control_dispatcher_) | 124 if (!control_dispatcher_) |
123 control_dispatcher_.reset(new ClientControlDispatcher()); | 125 control_dispatcher_.reset(new ClientControlDispatcher()); |
| 126 |
124 if (name == control_dispatcher_->channel_name() && | 127 if (name == control_dispatcher_->channel_name() && |
125 !control_dispatcher_->is_connected()) { | 128 !control_dispatcher_->is_connected()) { |
126 control_dispatcher_->set_client_stub(client_stub_); | 129 control_dispatcher_->set_client_stub(client_stub_); |
127 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | 130 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
128 control_dispatcher_->Init(std::move(pipe), this); | 131 control_dispatcher_->Init(std::move(pipe), this); |
| 132 } else if (base::StartsWith(name, kVideoStatsChannelNamePrefix, |
| 133 base::CompareCase::SENSITIVE)) { |
| 134 std::string video_stream_label = |
| 135 name.substr(strlen(kVideoStatsChannelNamePrefix)); |
| 136 GetOrCreateVideoAdapter(video_stream_label) |
| 137 ->SetVideoStatsChannel(std::move(pipe)); |
| 138 } else { |
| 139 LOG(WARNING) << "Received unknown incoming data channel " << name; |
129 } | 140 } |
130 } | 141 } |
131 | 142 |
132 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamAdded( | 143 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamAdded( |
133 scoped_refptr<webrtc::MediaStreamInterface> stream) { | 144 scoped_refptr<webrtc::MediaStreamInterface> stream) { |
134 if (video_adapter_) { | 145 GetOrCreateVideoAdapter(stream->label())->SetMediaStream(stream); |
135 LOG(WARNING) | |
136 << "Received multiple media streams. Ignoring all except the last one."; | |
137 } | |
138 video_adapter_.reset(new WebrtcVideoRendererAdapter(stream, video_renderer_)); | |
139 } | 146 } |
140 | 147 |
141 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamRemoved( | 148 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamRemoved( |
142 scoped_refptr<webrtc::MediaStreamInterface> stream) { | 149 scoped_refptr<webrtc::MediaStreamInterface> stream) { |
143 if (video_adapter_ && video_adapter_->label() == stream->label()) | 150 if (video_adapter_ && video_adapter_->label() == stream->label()) |
144 video_adapter_.reset(); | 151 video_adapter_.reset(); |
145 } | 152 } |
146 | 153 |
147 void WebrtcConnectionToHost::OnChannelInitialized( | 154 void WebrtcConnectionToHost::OnChannelInitialized( |
148 ChannelDispatcherBase* channel_dispatcher) { | 155 ChannelDispatcherBase* channel_dispatcher) { |
(...skipping 16 matching lines...) Expand all Loading... |
165 return; | 172 return; |
166 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) | 173 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) |
167 return; | 174 return; |
168 | 175 |
169 // Start forwarding clipboard and input events. | 176 // Start forwarding clipboard and input events. |
170 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); | 177 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); |
171 event_forwarder_.set_input_stub(event_dispatcher_.get()); | 178 event_forwarder_.set_input_stub(event_dispatcher_.get()); |
172 SetState(CONNECTED, OK); | 179 SetState(CONNECTED, OK); |
173 } | 180 } |
174 | 181 |
| 182 WebrtcVideoRendererAdapter* WebrtcConnectionToHost::GetOrCreateVideoAdapter( |
| 183 const std::string& label) { |
| 184 if (!video_adapter_ || video_adapter_->label() != label) { |
| 185 if (video_adapter_) { |
| 186 LOG(WARNING) << "Received multiple media streams. Ignoring all except " |
| 187 "the last one."; |
| 188 } |
| 189 video_adapter_.reset( |
| 190 new WebrtcVideoRendererAdapter(label, video_renderer_)); |
| 191 } |
| 192 return video_adapter_.get(); |
| 193 } |
| 194 |
175 void WebrtcConnectionToHost::CloseChannels() { | 195 void WebrtcConnectionToHost::CloseChannels() { |
176 clipboard_forwarder_.set_clipboard_stub(nullptr); | 196 clipboard_forwarder_.set_clipboard_stub(nullptr); |
177 control_dispatcher_.reset(); | 197 control_dispatcher_.reset(); |
178 event_forwarder_.set_input_stub(nullptr); | 198 event_forwarder_.set_input_stub(nullptr); |
179 event_dispatcher_.reset(); | 199 event_dispatcher_.reset(); |
180 } | 200 } |
181 | 201 |
182 void WebrtcConnectionToHost::SetState(State state, ErrorCode error) { | 202 void WebrtcConnectionToHost::SetState(State state, ErrorCode error) { |
183 // |error| should be specified only when |state| is set to FAILED. | 203 // |error| should be specified only when |state| is set to FAILED. |
184 DCHECK(state == FAILED || error == OK); | 204 DCHECK(state == FAILED || error == OK); |
185 | 205 |
186 if (state != state_) { | 206 if (state != state_) { |
187 state_ = state; | 207 state_ = state; |
188 error_ = error; | 208 error_ = error; |
189 event_callback_->OnConnectionState(state_, error_); | 209 event_callback_->OnConnectionState(state_, error_); |
190 } | 210 } |
191 } | 211 } |
192 | 212 |
193 } // namespace protocol | 213 } // namespace protocol |
194 } // namespace remoting | 214 } // namespace remoting |
OLD | NEW |