| 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/transport_context.h" | 14 #include "remoting/protocol/transport_context.h" |
| 15 #include "remoting/protocol/video_renderer.h" |
| 15 #include "remoting/protocol/webrtc_transport.h" | 16 #include "remoting/protocol/webrtc_transport.h" |
| 17 #include "remoting/protocol/webrtc_video_renderer_adapter.h" |
| 16 | 18 |
| 17 namespace remoting { | 19 namespace remoting { |
| 18 namespace protocol { | 20 namespace protocol { |
| 19 | 21 |
| 20 WebrtcConnectionToHost::WebrtcConnectionToHost() {} | 22 WebrtcConnectionToHost::WebrtcConnectionToHost() {} |
| 21 WebrtcConnectionToHost::~WebrtcConnectionToHost() {} | 23 WebrtcConnectionToHost::~WebrtcConnectionToHost() {} |
| 22 | 24 |
| 23 void WebrtcConnectionToHost::Connect( | 25 void WebrtcConnectionToHost::Connect( |
| 24 scoped_ptr<Session> session, | 26 scoped_ptr<Session> session, |
| 25 scoped_refptr<TransportContext> transport_context, | 27 scoped_refptr<TransportContext> transport_context, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 59 |
| 58 void WebrtcConnectionToHost::set_client_stub(ClientStub* client_stub) { | 60 void WebrtcConnectionToHost::set_client_stub(ClientStub* client_stub) { |
| 59 client_stub_ = client_stub; | 61 client_stub_ = client_stub; |
| 60 } | 62 } |
| 61 | 63 |
| 62 void WebrtcConnectionToHost::set_clipboard_stub(ClipboardStub* clipboard_stub) { | 64 void WebrtcConnectionToHost::set_clipboard_stub(ClipboardStub* clipboard_stub) { |
| 63 clipboard_stub_ = clipboard_stub; | 65 clipboard_stub_ = clipboard_stub; |
| 64 } | 66 } |
| 65 | 67 |
| 66 void WebrtcConnectionToHost::set_video_renderer(VideoRenderer* video_renderer) { | 68 void WebrtcConnectionToHost::set_video_renderer(VideoRenderer* video_renderer) { |
| 67 NOTIMPLEMENTED(); | 69 video_renderer_ = video_renderer; |
| 68 } | 70 } |
| 69 | 71 |
| 70 void WebrtcConnectionToHost::set_audio_stub(AudioStub* audio_stub) { | 72 void WebrtcConnectionToHost::set_audio_stub(AudioStub* audio_stub) { |
| 71 NOTIMPLEMENTED(); | 73 NOTIMPLEMENTED(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void WebrtcConnectionToHost::OnSessionStateChange(Session::State state) { | 76 void WebrtcConnectionToHost::OnSessionStateChange(Session::State state) { |
| 75 DCHECK(event_callback_); | 77 DCHECK(event_callback_); |
| 76 | 78 |
| 77 switch (state) { | 79 switch (state) { |
| 78 case Session::INITIALIZING: | 80 case Session::INITIALIZING: |
| 79 case Session::CONNECTING: | 81 case Session::CONNECTING: |
| 80 case Session::ACCEPTING: | 82 case Session::ACCEPTING: |
| 81 case Session::ACCEPTED: | 83 case Session::ACCEPTED: |
| 82 case Session::AUTHENTICATING: | 84 case Session::AUTHENTICATING: |
| 83 // Don't care about these events. | 85 // Don't care about these events. |
| 84 break; | 86 break; |
| 85 | 87 |
| 86 case Session::AUTHENTICATED: | 88 case Session::AUTHENTICATED: |
| 87 SetState(AUTHENTICATED, OK); | 89 SetState(AUTHENTICATED, OK); |
| 88 break; | 90 break; |
| 89 | 91 |
| 90 case Session::CLOSED: | 92 case Session::CLOSED: |
| 93 CloseChannels(); |
| 94 SetState(CLOSED, OK); |
| 95 break; |
| 96 |
| 91 case Session::FAILED: | 97 case Session::FAILED: |
| 92 CloseChannels(); | 98 CloseChannels(); |
| 93 SetState(CLOSED, state == Session::FAILED ? session_->error() : OK); | 99 SetState(FAILED, session_->error()); |
| 94 break; | 100 break; |
| 95 } | 101 } |
| 96 } | 102 } |
| 97 | 103 |
| 98 void WebrtcConnectionToHost::OnWebrtcTransportConnecting() { | 104 void WebrtcConnectionToHost::OnWebrtcTransportConnecting() { |
| 99 control_dispatcher_.reset(new ClientControlDispatcher()); | 105 control_dispatcher_.reset(new ClientControlDispatcher()); |
| 100 control_dispatcher_->Init(transport_->incoming_channel_factory(), this); | 106 control_dispatcher_->Init(transport_->incoming_channel_factory(), this); |
| 101 control_dispatcher_->set_client_stub(client_stub_); | 107 control_dispatcher_->set_client_stub(client_stub_); |
| 102 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | 108 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
| 103 | 109 |
| 104 event_dispatcher_.reset(new ClientEventDispatcher()); | 110 event_dispatcher_.reset(new ClientEventDispatcher()); |
| 105 event_dispatcher_->Init(transport_->outgoing_channel_factory(), this); | 111 event_dispatcher_->Init(transport_->outgoing_channel_factory(), this); |
| 106 } | 112 } |
| 107 | 113 |
| 108 void WebrtcConnectionToHost::OnWebrtcTransportConnected() {} | 114 void WebrtcConnectionToHost::OnWebrtcTransportConnected() {} |
| 109 | 115 |
| 110 void WebrtcConnectionToHost::OnWebrtcTransportError(ErrorCode error) { | 116 void WebrtcConnectionToHost::OnWebrtcTransportError(ErrorCode error) { |
| 111 CloseChannels(); | 117 CloseChannels(); |
| 112 SetState(FAILED, error); | 118 SetState(FAILED, error); |
| 113 } | 119 } |
| 114 | 120 |
| 121 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamAdded( |
| 122 scoped_refptr<webrtc::MediaStreamInterface> stream) { |
| 123 if (video_adapter_) { |
| 124 LOG(WARNING) |
| 125 << "Received multiple media streams. Ignoring all except the last one."; |
| 126 } |
| 127 video_adapter_.reset(new WebrtcVideoRendererAdapter( |
| 128 stream, video_renderer_->GetFrameConsumer())); |
| 129 } |
| 130 |
| 131 void WebrtcConnectionToHost::OnWebrtcTransportMediaStreamRemoved( |
| 132 scoped_refptr<webrtc::MediaStreamInterface> stream) { |
| 133 if (video_adapter_ && video_adapter_->label() == stream->label()) |
| 134 video_adapter_.reset(); |
| 135 } |
| 136 |
| 115 void WebrtcConnectionToHost::OnChannelInitialized( | 137 void WebrtcConnectionToHost::OnChannelInitialized( |
| 116 ChannelDispatcherBase* channel_dispatcher) { | 138 ChannelDispatcherBase* channel_dispatcher) { |
| 117 NotifyIfChannelsReady(); | 139 NotifyIfChannelsReady(); |
| 118 } | 140 } |
| 119 | 141 |
| 120 void WebrtcConnectionToHost::OnChannelError( | 142 void WebrtcConnectionToHost::OnChannelError( |
| 121 ChannelDispatcherBase* channel_dispatcher, | 143 ChannelDispatcherBase* channel_dispatcher, |
| 122 ErrorCode error) { | 144 ErrorCode error) { |
| 123 LOG(ERROR) << "Failed to connect channel " << channel_dispatcher; | 145 LOG(ERROR) << "Failed to connect channel " << channel_dispatcher; |
| 124 CloseChannels(); | 146 CloseChannels(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 154 | 176 |
| 155 if (state != state_) { | 177 if (state != state_) { |
| 156 state_ = state; | 178 state_ = state; |
| 157 error_ = error; | 179 error_ = error; |
| 158 event_callback_->OnConnectionState(state_, error_); | 180 event_callback_->OnConnectionState(state_, error_); |
| 159 } | 181 } |
| 160 } | 182 } |
| 161 | 183 |
| 162 } // namespace protocol | 184 } // namespace protocol |
| 163 } // namespace remoting | 185 } // namespace remoting |
| OLD | NEW |