| 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 "jingle/glue/thread_wrapper.h" | 9 #include "jingle/glue/thread_wrapper.h" |
| 10 #include "remoting/protocol/client_control_dispatcher.h" | 10 #include "remoting/protocol/client_control_dispatcher.h" |
| 11 #include "remoting/protocol/client_event_dispatcher.h" | 11 #include "remoting/protocol/client_event_dispatcher.h" |
| 12 #include "remoting/protocol/client_stub.h" | 12 #include "remoting/protocol/client_stub.h" |
| 13 #include "remoting/protocol/clipboard_stub.h" | 13 #include "remoting/protocol/clipboard_stub.h" |
| 14 #include "remoting/protocol/message_pipe.h" |
| 14 #include "remoting/protocol/transport_context.h" | 15 #include "remoting/protocol/transport_context.h" |
| 15 #include "remoting/protocol/video_renderer.h" | 16 #include "remoting/protocol/video_renderer.h" |
| 16 #include "remoting/protocol/webrtc_transport.h" | 17 #include "remoting/protocol/webrtc_transport.h" |
| 17 #include "remoting/protocol/webrtc_video_renderer_adapter.h" | 18 #include "remoting/protocol/webrtc_video_renderer_adapter.h" |
| 18 | 19 |
| 19 namespace remoting { | 20 namespace remoting { |
| 20 namespace protocol { | 21 namespace protocol { |
| 21 | 22 |
| 22 WebrtcConnectionToHost::WebrtcConnectionToHost() {} | 23 WebrtcConnectionToHost::WebrtcConnectionToHost() {} |
| 23 WebrtcConnectionToHost::~WebrtcConnectionToHost() {} | 24 WebrtcConnectionToHost::~WebrtcConnectionToHost() {} |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 break; | 96 break; |
| 96 | 97 |
| 97 case Session::FAILED: | 98 case Session::FAILED: |
| 98 CloseChannels(); | 99 CloseChannels(); |
| 99 SetState(FAILED, session_->error()); | 100 SetState(FAILED, session_->error()); |
| 100 break; | 101 break; |
| 101 } | 102 } |
| 102 } | 103 } |
| 103 | 104 |
| 104 void WebrtcConnectionToHost::OnWebrtcTransportConnecting() { | 105 void WebrtcConnectionToHost::OnWebrtcTransportConnecting() { |
| 105 control_dispatcher_.reset(new ClientControlDispatcher()); | |
| 106 control_dispatcher_->Init(transport_->incoming_channel_factory(), this); | |
| 107 control_dispatcher_->set_client_stub(client_stub_); | |
| 108 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | |
| 109 | |
| 110 event_dispatcher_.reset(new ClientEventDispatcher()); | 106 event_dispatcher_.reset(new ClientEventDispatcher()); |
| 111 event_dispatcher_->Init(transport_->outgoing_channel_factory(), this); | 107 event_dispatcher_->Init(transport_->outgoing_channel_factory(), this); |
| 112 } | 108 } |
| 113 | 109 |
| 114 void WebrtcConnectionToHost::OnWebrtcTransportConnected() {} | 110 void WebrtcConnectionToHost::OnWebrtcTransportConnected() {} |
| 115 | 111 |
| 116 void WebrtcConnectionToHost::OnWebrtcTransportError(ErrorCode error) { | 112 void WebrtcConnectionToHost::OnWebrtcTransportError(ErrorCode error) { |
| 117 CloseChannels(); | 113 CloseChannels(); |
| 118 SetState(FAILED, error); | 114 SetState(FAILED, error); |
| 119 } | 115 } |
| 120 | 116 |
| 117 void WebrtcConnectionToHost::OnWebrtcTransportIncomingDataChannel( |
| 118 const std::string& name, |
| 119 std::unique_ptr<MessagePipe> pipe) { |
| 120 if (!control_dispatcher_) |
| 121 control_dispatcher_.reset(new ClientControlDispatcher()); |
| 122 if (name == control_dispatcher_->channel_name() && |
| 123 !control_dispatcher_->is_connected()) { |
| 124 control_dispatcher_->set_client_stub(client_stub_); |
| 125 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
| 126 control_dispatcher_->Init(std::move(pipe), this); |
| 127 } |
| 128 } |
| 129 |
| 121 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamAdded( | 130 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamAdded( |
| 122 scoped_refptr<webrtc::MediaStreamInterface> stream) { | 131 scoped_refptr<webrtc::MediaStreamInterface> stream) { |
| 123 if (video_adapter_) { | 132 if (video_adapter_) { |
| 124 LOG(WARNING) | 133 LOG(WARNING) |
| 125 << "Received multiple media streams. Ignoring all except the last one."; | 134 << "Received multiple media streams. Ignoring all except the last one."; |
| 126 } | 135 } |
| 127 video_adapter_.reset(new WebrtcVideoRendererAdapter(stream, video_renderer_)); | 136 video_adapter_.reset(new WebrtcVideoRendererAdapter(stream, video_renderer_)); |
| 128 } | 137 } |
| 129 | 138 |
| 130 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamRemoved( | 139 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamRemoved( |
| 131 scoped_refptr<webrtc::MediaStreamInterface> stream) { | 140 scoped_refptr<webrtc::MediaStreamInterface> stream) { |
| 132 if (video_adapter_ && video_adapter_->label() == stream->label()) | 141 if (video_adapter_ && video_adapter_->label() == stream->label()) |
| 133 video_adapter_.reset(); | 142 video_adapter_.reset(); |
| 134 } | 143 } |
| 135 | 144 |
| 136 void WebrtcConnectionToHost::OnChannelInitialized( | 145 void WebrtcConnectionToHost::OnChannelInitialized( |
| 137 ChannelDispatcherBase* channel_dispatcher) { | 146 ChannelDispatcherBase* channel_dispatcher) { |
| 138 NotifyIfChannelsReady(); | 147 NotifyIfChannelsReady(); |
| 139 } | 148 } |
| 140 | 149 |
| 150 void WebrtcConnectionToHost::OnChannelClosed( |
| 151 ChannelDispatcherBase* channel_dispatcher) { |
| 152 LOG(ERROR) << "Channel " << channel_dispatcher->channel_name() |
| 153 << " was closed unexpectedly."; |
| 154 SetState(FAILED, INCOMPATIBLE_PROTOCOL); |
| 155 } |
| 156 |
| 141 ConnectionToHost::State WebrtcConnectionToHost::state() const { | 157 ConnectionToHost::State WebrtcConnectionToHost::state() const { |
| 142 return state_; | 158 return state_; |
| 143 } | 159 } |
| 144 | 160 |
| 145 void WebrtcConnectionToHost::NotifyIfChannelsReady() { | 161 void WebrtcConnectionToHost::NotifyIfChannelsReady() { |
| 146 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) | 162 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) |
| 147 return; | 163 return; |
| 148 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) | 164 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) |
| 149 return; | 165 return; |
| 150 | 166 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 167 | 183 |
| 168 if (state != state_) { | 184 if (state != state_) { |
| 169 state_ = state; | 185 state_ = state; |
| 170 error_ = error; | 186 error_ = error; |
| 171 event_callback_->OnConnectionState(state_, error_); | 187 event_callback_->OnConnectionState(state_, error_); |
| 172 } | 188 } |
| 173 } | 189 } |
| 174 | 190 |
| 175 } // namespace protocol | 191 } // namespace protocol |
| 176 } // namespace remoting | 192 } // namespace remoting |
| OLD | NEW |