| 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_source.h" | 15 #include "remoting/protocol/audio_source.h" |
| 16 #include "remoting/protocol/audio_stream.h" | 16 #include "remoting/protocol/audio_stream.h" |
| 17 #include "remoting/protocol/clipboard_stub.h" | 17 #include "remoting/protocol/clipboard_stub.h" |
| 18 #include "remoting/protocol/host_control_dispatcher.h" | 18 #include "remoting/protocol/host_control_dispatcher.h" |
| 19 #include "remoting/protocol/host_event_dispatcher.h" | 19 #include "remoting/protocol/host_event_dispatcher.h" |
| 20 #include "remoting/protocol/host_stub.h" | 20 #include "remoting/protocol/host_stub.h" |
| 21 #include "remoting/protocol/input_stub.h" | 21 #include "remoting/protocol/input_stub.h" |
| 22 #include "remoting/protocol/message_pipe.h" | 22 #include "remoting/protocol/message_pipe.h" |
| 23 #include "remoting/protocol/process_stats_dispatcher.h" |
| 24 #include "remoting/protocol/process_stats_stub.h" |
| 23 #include "remoting/protocol/transport_context.h" | 25 #include "remoting/protocol/transport_context.h" |
| 24 #include "remoting/protocol/webrtc_audio_stream.h" | 26 #include "remoting/protocol/webrtc_audio_stream.h" |
| 25 #include "remoting/protocol/webrtc_transport.h" | 27 #include "remoting/protocol/webrtc_transport.h" |
| 26 #include "remoting/protocol/webrtc_video_stream.h" | 28 #include "remoting/protocol/webrtc_video_stream.h" |
| 27 #include "third_party/webrtc/api/mediastreaminterface.h" | 29 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 28 #include "third_party/webrtc/api/peerconnectioninterface.h" | 30 #include "third_party/webrtc/api/peerconnectioninterface.h" |
| 29 #include "third_party/webrtc/api/test/fakeconstraints.h" | 31 #include "third_party/webrtc/api/test/fakeconstraints.h" |
| 30 | 32 |
| 31 namespace remoting { | 33 namespace remoting { |
| 32 namespace protocol { | 34 namespace protocol { |
| 33 | 35 |
| 34 // Currently the network thread is also used as worker thread for webrtc. | 36 // Currently the network thread is also used as worker thread for webrtc. |
| 35 // | 37 // |
| 36 // TODO(sergeyu): Figure out if we would benefit from using a separate | 38 // TODO(sergeyu): Figure out if we would benefit from using a separate |
| 37 // thread as a worker thread. | 39 // thread as a worker thread. |
| 38 WebrtcConnectionToClient::WebrtcConnectionToClient( | 40 WebrtcConnectionToClient::WebrtcConnectionToClient( |
| 39 std::unique_ptr<protocol::Session> session, | 41 std::unique_ptr<protocol::Session> session, |
| 40 scoped_refptr<protocol::TransportContext> transport_context, | 42 scoped_refptr<protocol::TransportContext> transport_context, |
| 41 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, | 43 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, |
| 42 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner) | 44 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner) |
| 43 : transport_( | 45 : transport_( |
| 44 new WebrtcTransport(jingle_glue::JingleThreadWrapper::current(), | 46 new WebrtcTransport(jingle_glue::JingleThreadWrapper::current(), |
| 45 transport_context, | 47 transport_context, |
| 46 this)), | 48 this)), |
| 47 session_(std::move(session)), | 49 session_(std::move(session)), |
| 48 video_encode_task_runner_(video_encode_task_runner), | 50 video_encode_task_runner_(video_encode_task_runner), |
| 49 audio_task_runner_(audio_task_runner), | 51 audio_task_runner_(audio_task_runner), |
| 50 control_dispatcher_(new HostControlDispatcher()), | 52 control_dispatcher_(new HostControlDispatcher()), |
| 51 event_dispatcher_(new HostEventDispatcher()), | 53 event_dispatcher_(new HostEventDispatcher()), |
| 54 stats_dispatcher_(new ProcessStatsDispatcher()), |
| 52 weak_factory_(this) { | 55 weak_factory_(this) { |
| 53 session_->SetEventHandler(this); | 56 session_->SetEventHandler(this); |
| 54 session_->SetTransport(transport_.get()); | 57 session_->SetTransport(transport_.get()); |
| 55 } | 58 } |
| 56 | 59 |
| 57 WebrtcConnectionToClient::~WebrtcConnectionToClient() {} | 60 WebrtcConnectionToClient::~WebrtcConnectionToClient() {} |
| 58 | 61 |
| 59 void WebrtcConnectionToClient::SetEventHandler( | 62 void WebrtcConnectionToClient::SetEventHandler( |
| 60 ConnectionToClient::EventHandler* event_handler) { | 63 ConnectionToClient::EventHandler* event_handler) { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 stream->Start(audio_task_runner_, std::move(audio_source), transport_.get()); | 100 stream->Start(audio_task_runner_, std::move(audio_source), transport_.get()); |
| 98 return std::move(stream); | 101 return std::move(stream); |
| 99 } | 102 } |
| 100 | 103 |
| 101 // Return pointer to ClientStub. | 104 // Return pointer to ClientStub. |
| 102 ClientStub* WebrtcConnectionToClient::client_stub() { | 105 ClientStub* WebrtcConnectionToClient::client_stub() { |
| 103 DCHECK(thread_checker_.CalledOnValidThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
| 104 return control_dispatcher_.get(); | 107 return control_dispatcher_.get(); |
| 105 } | 108 } |
| 106 | 109 |
| 110 // Return pointer to ProcessStatsStub. |
| 111 ProcessStatsStub* WebrtcConnectionToClient::stats_stub() { |
| 112 DCHECK(thread_checker_.CalledOnValidThread()); |
| 113 return stats_dispatcher_.get(); |
| 114 } |
| 115 |
| 107 void WebrtcConnectionToClient::set_clipboard_stub( | 116 void WebrtcConnectionToClient::set_clipboard_stub( |
| 108 protocol::ClipboardStub* clipboard_stub) { | 117 protocol::ClipboardStub* clipboard_stub) { |
| 109 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 110 control_dispatcher_->set_clipboard_stub(clipboard_stub); | 119 control_dispatcher_->set_clipboard_stub(clipboard_stub); |
| 111 } | 120 } |
| 112 | 121 |
| 113 void WebrtcConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { | 122 void WebrtcConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { |
| 114 DCHECK(thread_checker_.CalledOnValidThread()); | 123 DCHECK(thread_checker_.CalledOnValidThread()); |
| 115 control_dispatcher_->set_host_stub(host_stub); | 124 control_dispatcher_->set_host_stub(host_stub); |
| 116 } | 125 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 144 // being torn down. | 153 // being torn down. |
| 145 if (self) | 154 if (self) |
| 146 event_handler_->CreateMediaStreams(); | 155 event_handler_->CreateMediaStreams(); |
| 147 break; | 156 break; |
| 148 } | 157 } |
| 149 | 158 |
| 150 case Session::CLOSED: | 159 case Session::CLOSED: |
| 151 case Session::FAILED: | 160 case Session::FAILED: |
| 152 control_dispatcher_.reset(); | 161 control_dispatcher_.reset(); |
| 153 event_dispatcher_.reset(); | 162 event_dispatcher_.reset(); |
| 163 stats_dispatcher_.reset(); |
| 154 transport_->Close(state == Session::CLOSED ? OK : session_->error()); | 164 transport_->Close(state == Session::CLOSED ? OK : session_->error()); |
| 155 transport_.reset(); | 165 transport_.reset(); |
| 156 event_handler_->OnConnectionClosed( | 166 event_handler_->OnConnectionClosed( |
| 157 state == Session::CLOSED ? OK : session_->error()); | 167 state == Session::CLOSED ? OK : session_->error()); |
| 158 break; | 168 break; |
| 159 } | 169 } |
| 160 } | 170 } |
| 161 | 171 |
| 162 void WebrtcConnectionToClient::OnWebrtcTransportConnecting() { | 172 void WebrtcConnectionToClient::OnWebrtcTransportConnecting() { |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | 173 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 ChannelDispatcherBase* channel_dispatcher) { | 222 ChannelDispatcherBase* channel_dispatcher) { |
| 213 DCHECK(thread_checker_.CalledOnValidThread()); | 223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 214 | 224 |
| 215 LOG(ERROR) << "Channel " << channel_dispatcher->channel_name() | 225 LOG(ERROR) << "Channel " << channel_dispatcher->channel_name() |
| 216 << " was closed unexpectedly."; | 226 << " was closed unexpectedly."; |
| 217 Disconnect(INCOMPATIBLE_PROTOCOL); | 227 Disconnect(INCOMPATIBLE_PROTOCOL); |
| 218 } | 228 } |
| 219 | 229 |
| 220 } // namespace protocol | 230 } // namespace protocol |
| 221 } // namespace remoting | 231 } // namespace remoting |
| OLD | NEW |