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_client.h" | 5 #include "remoting/protocol/webrtc_connection_to_client.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "jingle/glue/thread_wrapper.h" | 11 #include "jingle/glue/thread_wrapper.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "remoting/codec/video_encoder.h" | 13 #include "remoting/codec/video_encoder.h" |
14 #include "remoting/codec/webrtc_video_encoder_vpx.h" | 14 #include "remoting/codec/webrtc_video_encoder_vpx.h" |
15 #include "remoting/protocol/audio_writer.h" | 15 #include "remoting/protocol/audio_writer.h" |
16 #include "remoting/protocol/clipboard_stub.h" | 16 #include "remoting/protocol/clipboard_stub.h" |
17 #include "remoting/protocol/host_control_dispatcher.h" | 17 #include "remoting/protocol/host_control_dispatcher.h" |
18 #include "remoting/protocol/host_event_dispatcher.h" | 18 #include "remoting/protocol/host_event_dispatcher.h" |
19 #include "remoting/protocol/host_stub.h" | 19 #include "remoting/protocol/host_stub.h" |
20 #include "remoting/protocol/input_stub.h" | 20 #include "remoting/protocol/input_stub.h" |
21 #include "remoting/protocol/message_pipe.h" | |
21 #include "remoting/protocol/transport_context.h" | 22 #include "remoting/protocol/transport_context.h" |
22 #include "remoting/protocol/webrtc_transport.h" | 23 #include "remoting/protocol/webrtc_transport.h" |
23 #include "remoting/protocol/webrtc_video_stream.h" | 24 #include "remoting/protocol/webrtc_video_stream.h" |
24 #include "third_party/webrtc/api/mediastreaminterface.h" | 25 #include "third_party/webrtc/api/mediastreaminterface.h" |
25 #include "third_party/webrtc/api/peerconnectioninterface.h" | 26 #include "third_party/webrtc/api/peerconnectioninterface.h" |
26 #include "third_party/webrtc/api/test/fakeconstraints.h" | 27 #include "third_party/webrtc/api/test/fakeconstraints.h" |
27 | 28 |
28 namespace remoting { | 29 namespace remoting { |
29 namespace protocol { | 30 namespace protocol { |
30 | 31 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 138 |
138 // OnConnectionAuthenticated() call above may result in the connection | 139 // OnConnectionAuthenticated() call above may result in the connection |
139 // being torn down. | 140 // being torn down. |
140 if (self) | 141 if (self) |
141 event_handler_->CreateVideoStreams(this); | 142 event_handler_->CreateVideoStreams(this); |
142 break; | 143 break; |
143 } | 144 } |
144 | 145 |
145 case Session::CLOSED: | 146 case Session::CLOSED: |
146 case Session::FAILED: | 147 case Session::FAILED: |
147 transport_->Close(state == Session::CLOSED ? OK : session_->error()); | |
148 control_dispatcher_.reset(); | 148 control_dispatcher_.reset(); |
149 event_dispatcher_.reset(); | 149 event_dispatcher_.reset(); |
150 transport_->Close(state == Session::CLOSED ? OK : session_->error()); | |
150 event_handler_->OnConnectionClosed( | 151 event_handler_->OnConnectionClosed( |
151 this, state == Session::CLOSED ? OK : session_->error()); | 152 this, state == Session::CLOSED ? OK : session_->error()); |
152 break; | 153 break; |
153 } | 154 } |
154 } | 155 } |
155 | 156 |
156 void WebrtcConnectionToClient::OnWebrtcTransportConnecting() { | 157 void WebrtcConnectionToClient::OnWebrtcTransportConnecting() { |
158 // Create outgoing control channel by initializing |control_dispatcher_|. | |
159 // |event_dispatcher_| is initialized later because event channel is expected | |
160 // to be created by the client. | |
157 control_dispatcher_->Init(transport_->outgoing_channel_factory(), this); | 161 control_dispatcher_->Init(transport_->outgoing_channel_factory(), this); |
158 | |
159 event_dispatcher_->Init(transport_->incoming_channel_factory(), this); | |
160 event_dispatcher_->set_on_input_event_callback(base::Bind( | |
161 &ConnectionToClient::OnInputEventReceived, base::Unretained(this))); | |
162 } | 162 } |
163 | 163 |
164 void WebrtcConnectionToClient::OnWebrtcTransportConnected() { | 164 void WebrtcConnectionToClient::OnWebrtcTransportConnected() { |
165 DCHECK(thread_checker_.CalledOnValidThread()); | 165 DCHECK(thread_checker_.CalledOnValidThread()); |
166 } | 166 } |
167 | 167 |
168 void WebrtcConnectionToClient::OnWebrtcTransportError(ErrorCode error) { | 168 void WebrtcConnectionToClient::OnWebrtcTransportError(ErrorCode error) { |
169 DCHECK(thread_checker_.CalledOnValidThread()); | 169 DCHECK(thread_checker_.CalledOnValidThread()); |
170 Disconnect(error); | 170 Disconnect(error); |
171 } | 171 } |
172 | 172 |
173 void WebrtcConnectionToClient::OnWebrtcTransportIncomingDataChannel( | |
174 const std::string& name, | |
175 std::unique_ptr<MessagePipe> pipe) { | |
176 if (name == event_dispatcher_->channel_name() && | |
177 !event_dispatcher_->is_connected()) { | |
178 event_dispatcher_->set_on_input_event_callback(base::Bind( | |
179 &ConnectionToClient::OnInputEventReceived, base::Unretained(this))); | |
180 event_dispatcher_->Init(std::move(pipe), this); | |
181 } | |
182 } | |
183 | |
173 void WebrtcConnectionToClient::OnWebrtcTransportMediaStreamAdded( | 184 void WebrtcConnectionToClient::OnWebrtcTransportMediaStreamAdded( |
174 scoped_refptr<webrtc::MediaStreamInterface> stream) { | 185 scoped_refptr<webrtc::MediaStreamInterface> stream) { |
175 LOG(WARNING) << "The client created an unexpected media stream."; | 186 LOG(WARNING) << "The client created an unexpected media stream."; |
176 } | 187 } |
177 | 188 |
178 void WebrtcConnectionToClient::OnWebrtcTransportMediaStreamRemoved( | 189 void WebrtcConnectionToClient::OnWebrtcTransportMediaStreamRemoved( |
179 scoped_refptr<webrtc::MediaStreamInterface> stream) {} | 190 scoped_refptr<webrtc::MediaStreamInterface> stream) {} |
180 | 191 |
181 void WebrtcConnectionToClient::OnChannelInitialized( | 192 void WebrtcConnectionToClient::OnChannelInitialized( |
182 ChannelDispatcherBase* channel_dispatcher) { | 193 ChannelDispatcherBase* channel_dispatcher) { |
183 DCHECK(thread_checker_.CalledOnValidThread()); | 194 DCHECK(thread_checker_.CalledOnValidThread()); |
184 | 195 |
185 if (control_dispatcher_ && control_dispatcher_->is_connected() && | 196 if (control_dispatcher_ && control_dispatcher_->is_connected() && |
186 event_dispatcher_ && event_dispatcher_->is_connected()) { | 197 event_dispatcher_ && event_dispatcher_->is_connected()) { |
187 event_handler_->OnConnectionChannelsConnected(this); | 198 event_handler_->OnConnectionChannelsConnected(this); |
188 } | 199 } |
189 } | 200 } |
190 | 201 |
202 void WebrtcConnectionToClient::OnChannelClosed( | |
203 ChannelDispatcherBase* channel_dispatcher) { | |
204 DCHECK(thread_checker_.CalledOnValidThread()); | |
205 | |
206 DCHECK(false); | |
Jamie
2016/07/20 00:31:39
Left-over debugging?
Sergey Ulanov
2016/07/20 01:18:22
Done.
| |
207 LOG(ERROR) << "Channel " << channel_dispatcher->channel_name() | |
208 << " was closed unexpectedly."; | |
209 Disconnect(INCOMPATIBLE_PROTOCOL); | |
210 } | |
211 | |
191 } // namespace protocol | 212 } // namespace protocol |
192 } // namespace remoting | 213 } // namespace remoting |
OLD | NEW |