| 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/video_encoder_verbatim.h" | 14 #include "remoting/codec/video_encoder_verbatim.h" |
| 15 #include "remoting/codec/video_encoder_vpx.h" | 15 #include "remoting/codec/video_encoder_vpx.h" |
| 16 #include "remoting/protocol/audio_writer.h" | 16 #include "remoting/protocol/audio_writer.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/transport_context.h" | 22 #include "remoting/protocol/transport_context.h" |
| 23 #include "remoting/protocol/webrtc_transport.h" | 23 #include "remoting/protocol/webrtc_transport.h" |
| 24 #include "remoting/protocol/webrtc_video_capturer_adapter.h" | |
| 25 #include "remoting/protocol/webrtc_video_stream.h" | 24 #include "remoting/protocol/webrtc_video_stream.h" |
| 26 #include "third_party/webrtc/api/mediastreaminterface.h" | 25 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 27 #include "third_party/webrtc/api/peerconnectioninterface.h" | 26 #include "third_party/webrtc/api/peerconnectioninterface.h" |
| 28 #include "third_party/webrtc/api/test/fakeconstraints.h" | 27 #include "third_party/webrtc/api/test/fakeconstraints.h" |
| 29 | 28 |
| 30 namespace remoting { | 29 namespace remoting { |
| 31 namespace protocol { | 30 namespace protocol { |
| 32 | 31 |
| 33 // Currently the network thread is also used as worker thread for webrtc. | 32 // Currently the network thread is also used as worker thread for webrtc. |
| 34 // | 33 // |
| 35 // TODO(sergeyu): Figure out if we would benefit from using a separate | 34 // TODO(sergeyu): Figure out if we would benefit from using a separate |
| 36 // thread as a worker thread. | 35 // thread as a worker thread. |
| 37 WebrtcConnectionToClient::WebrtcConnectionToClient( | 36 WebrtcConnectionToClient::WebrtcConnectionToClient( |
| 38 scoped_ptr<protocol::Session> session, | 37 scoped_ptr<protocol::Session> session, |
| 39 scoped_refptr<protocol::TransportContext> transport_context) | 38 scoped_refptr<protocol::TransportContext> transport_context, |
| 40 : transport_(jingle_glue::JingleThreadWrapper::current(), | 39 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner) |
| 41 transport_context, | 40 : transport_( |
| 42 this), | 41 new WebrtcTransport(jingle_glue::JingleThreadWrapper::current(), |
| 42 transport_context, |
| 43 this)), |
| 43 session_(std::move(session)), | 44 session_(std::move(session)), |
| 45 video_encode_task_runner_(video_encode_task_runner), |
| 44 control_dispatcher_(new HostControlDispatcher()), | 46 control_dispatcher_(new HostControlDispatcher()), |
| 45 event_dispatcher_(new HostEventDispatcher()) { | 47 event_dispatcher_(new HostEventDispatcher()) { |
| 46 session_->SetEventHandler(this); | 48 session_->SetEventHandler(this); |
| 47 session_->SetTransport(&transport_); | 49 session_->SetTransport(transport_.get()); |
| 48 } | 50 } |
| 49 | 51 |
| 50 WebrtcConnectionToClient::~WebrtcConnectionToClient() {} | 52 WebrtcConnectionToClient::~WebrtcConnectionToClient() {} |
| 51 | 53 |
| 52 void WebrtcConnectionToClient::SetEventHandler( | 54 void WebrtcConnectionToClient::SetEventHandler( |
| 53 ConnectionToClient::EventHandler* event_handler) { | 55 ConnectionToClient::EventHandler* event_handler) { |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 event_handler_ = event_handler; | 57 event_handler_ = event_handler; |
| 56 } | 58 } |
| 57 | 59 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 session_->Close(error); | 70 session_->Close(error); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void WebrtcConnectionToClient::OnInputEventReceived(int64_t timestamp) { | 73 void WebrtcConnectionToClient::OnInputEventReceived(int64_t timestamp) { |
| 72 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
| 73 event_handler_->OnInputEventReceived(this, timestamp); | 75 event_handler_->OnInputEventReceived(this, timestamp); |
| 74 } | 76 } |
| 75 | 77 |
| 76 scoped_ptr<VideoStream> WebrtcConnectionToClient::StartVideoStream( | 78 scoped_ptr<VideoStream> WebrtcConnectionToClient::StartVideoStream( |
| 77 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer) { | 79 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer) { |
| 80 // TODO(isheriff): make this codec independent |
| 81 scoped_ptr<VideoEncoder> video_encoder = VideoEncoderVpx::CreateForVP8(); |
| 78 scoped_ptr<WebrtcVideoStream> stream(new WebrtcVideoStream()); | 82 scoped_ptr<WebrtcVideoStream> stream(new WebrtcVideoStream()); |
| 79 if (!stream->Start(std::move(desktop_capturer), transport_.peer_connection(), | 83 if (!stream->Start(std::move(desktop_capturer), transport_.get(), |
| 80 transport_.peer_connection_factory())) { | 84 video_encode_task_runner_, std::move(video_encoder))) { |
| 81 return nullptr; | 85 return nullptr; |
| 82 } | 86 } |
| 83 return std::move(stream); | 87 return std::move(stream); |
| 84 | |
| 85 } | 88 } |
| 86 | 89 |
| 87 AudioStub* WebrtcConnectionToClient::audio_stub() { | 90 AudioStub* WebrtcConnectionToClient::audio_stub() { |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 return nullptr; | 92 return nullptr; |
| 90 } | 93 } |
| 91 | 94 |
| 92 // Return pointer to ClientStub. | 95 // Return pointer to ClientStub. |
| 93 ClientStub* WebrtcConnectionToClient::client_stub() { | 96 ClientStub* WebrtcConnectionToClient::client_stub() { |
| 94 DCHECK(thread_checker_.CalledOnValidThread()); | 97 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 | 111 |
| 109 void WebrtcConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { | 112 void WebrtcConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { |
| 110 DCHECK(thread_checker_.CalledOnValidThread()); | 113 DCHECK(thread_checker_.CalledOnValidThread()); |
| 111 event_dispatcher_->set_input_stub(input_stub); | 114 event_dispatcher_->set_input_stub(input_stub); |
| 112 } | 115 } |
| 113 | 116 |
| 114 void WebrtcConnectionToClient::OnSessionStateChange(Session::State state) { | 117 void WebrtcConnectionToClient::OnSessionStateChange(Session::State state) { |
| 115 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 116 | 119 |
| 117 DCHECK(event_handler_); | 120 DCHECK(event_handler_); |
| 118 switch(state) { | 121 switch (state) { |
| 119 case Session::INITIALIZING: | 122 case Session::INITIALIZING: |
| 120 case Session::CONNECTING: | 123 case Session::CONNECTING: |
| 121 case Session::ACCEPTING: | 124 case Session::ACCEPTING: |
| 122 case Session::ACCEPTED: | 125 case Session::ACCEPTED: |
| 123 // Don't care about these events. | 126 // Don't care about these events. |
| 124 break; | 127 break; |
| 125 case Session::AUTHENTICATING: | 128 case Session::AUTHENTICATING: |
| 126 event_handler_->OnConnectionAuthenticating(this); | 129 event_handler_->OnConnectionAuthenticating(this); |
| 127 break; | 130 break; |
| 128 case Session::AUTHENTICATED: | 131 case Session::AUTHENTICATED: |
| 129 event_handler_->OnConnectionAuthenticated(this); | 132 event_handler_->OnConnectionAuthenticated(this); |
| 130 break; | 133 break; |
| 131 case Session::CLOSED: | 134 case Session::CLOSED: |
| 132 case Session::FAILED: | 135 case Session::FAILED: |
| 136 transport_->Close(state == Session::CLOSED ? OK : session_->error()); |
| 133 control_dispatcher_.reset(); | 137 control_dispatcher_.reset(); |
| 134 event_dispatcher_.reset(); | 138 event_dispatcher_.reset(); |
| 135 event_handler_->OnConnectionClosed( | 139 event_handler_->OnConnectionClosed( |
| 136 this, state == Session::CLOSED ? OK : session_->error()); | 140 this, state == Session::CLOSED ? OK : session_->error()); |
| 137 break; | 141 break; |
| 138 } | 142 } |
| 139 } | 143 } |
| 140 | 144 |
| 141 void WebrtcConnectionToClient::OnWebrtcTransportConnecting() { | 145 void WebrtcConnectionToClient::OnWebrtcTransportConnecting() { |
| 142 control_dispatcher_->Init(transport_.outgoing_channel_factory(), this); | 146 control_dispatcher_->Init(transport_->outgoing_channel_factory(), this); |
| 143 | 147 |
| 144 event_dispatcher_->Init(transport_.incoming_channel_factory(), this); | 148 event_dispatcher_->Init(transport_->incoming_channel_factory(), this); |
| 145 event_dispatcher_->set_on_input_event_callback(base::Bind( | 149 event_dispatcher_->set_on_input_event_callback(base::Bind( |
| 146 &ConnectionToClient::OnInputEventReceived, base::Unretained(this))); | 150 &ConnectionToClient::OnInputEventReceived, base::Unretained(this))); |
| 147 } | 151 } |
| 148 | 152 |
| 149 void WebrtcConnectionToClient::OnWebrtcTransportConnected() { | 153 void WebrtcConnectionToClient::OnWebrtcTransportConnected() { |
| 150 DCHECK(thread_checker_.CalledOnValidThread()); | 154 DCHECK(thread_checker_.CalledOnValidThread()); |
| 151 } | 155 } |
| 152 | 156 |
| 153 void WebrtcConnectionToClient::OnWebrtcTransportError(ErrorCode error) { | 157 void WebrtcConnectionToClient::OnWebrtcTransportError(ErrorCode error) { |
| 154 DCHECK(thread_checker_.CalledOnValidThread()); | 158 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 168 DCHECK(thread_checker_.CalledOnValidThread()); | 172 DCHECK(thread_checker_.CalledOnValidThread()); |
| 169 | 173 |
| 170 if (control_dispatcher_ && control_dispatcher_->is_connected() && | 174 if (control_dispatcher_ && control_dispatcher_->is_connected() && |
| 171 event_dispatcher_ && event_dispatcher_->is_connected()) { | 175 event_dispatcher_ && event_dispatcher_->is_connected()) { |
| 172 event_handler_->OnConnectionChannelsConnected(this); | 176 event_handler_->OnConnectionChannelsConnected(this); |
| 173 } | 177 } |
| 174 } | 178 } |
| 175 | 179 |
| 176 } // namespace protocol | 180 } // namespace protocol |
| 177 } // namespace remoting | 181 } // namespace remoting |
| OLD | NEW |