| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/host/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
| 6 | 6 |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "base/task.h" | 8 #include "base/task.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| 11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 12 #include "remoting/host/capturer_gdi.h" | 12 #include "remoting/host/capturer_gdi.h" |
| 13 #include "remoting/host/event_executor_win.h" | 13 #include "remoting/host/event_executor_win.h" |
| 14 #elif defined(OS_LINUX) | 14 #elif defined(OS_LINUX) |
| 15 #include "remoting/host/capturer_linux.h" | 15 #include "remoting/host/capturer_linux.h" |
| 16 #include "remoting/host/event_executor_linux.h" | 16 #include "remoting/host/event_executor_linux.h" |
| 17 #elif defined(OS_MACOSX) | 17 #elif defined(OS_MACOSX) |
| 18 #include "remoting/host/capturer_mac.h" | 18 #include "remoting/host/capturer_mac.h" |
| 19 #include "remoting/host/event_executor_mac.h" | 19 #include "remoting/host/event_executor_mac.h" |
| 20 #endif | 20 #endif |
| 21 #include "remoting/base/encoder.h" | 21 #include "remoting/base/encoder.h" |
| 22 #include "remoting/base/encoder_verbatim.h" | 22 #include "remoting/base/encoder_verbatim.h" |
| 23 #include "remoting/base/encoder_vp8.h" | 23 #include "remoting/base/encoder_vp8.h" |
| 24 #include "remoting/base/encoder_zlib.h" | 24 #include "remoting/base/encoder_zlib.h" |
| 25 #include "remoting/host/chromoting_host_context.h" | 25 #include "remoting/host/chromoting_host_context.h" |
| 26 #include "remoting/host/host_config.h" | 26 #include "remoting/host/host_config.h" |
| 27 #include "remoting/host/host_stub_fake.h" | 27 #include "remoting/host/host_stub_fake.h" |
| 28 #include "remoting/host/session_manager.h" | 28 #include "remoting/host/screen_recorder.h" |
| 29 #include "remoting/protocol/connection_to_client.h" | 29 #include "remoting/protocol/connection_to_client.h" |
| 30 #include "remoting/protocol/host_stub.h" | 30 #include "remoting/protocol/host_stub.h" |
| 31 #include "remoting/protocol/input_stub.h" | 31 #include "remoting/protocol/input_stub.h" |
| 32 #include "remoting/protocol/jingle_session_manager.h" | 32 #include "remoting/protocol/jingle_session_manager.h" |
| 33 #include "remoting/protocol/session_config.h" | 33 #include "remoting/protocol/session_config.h" |
| 34 | 34 |
| 35 using remoting::protocol::ConnectionToClient; | 35 using remoting::protocol::ConnectionToClient; |
| 36 | 36 |
| 37 namespace remoting { | 37 namespace remoting { |
| 38 | 38 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 { | 140 { |
| 141 AutoLock auto_lock(lock_); | 141 AutoLock auto_lock(lock_); |
| 142 if (state_ != kStarted) { | 142 if (state_ != kStarted) { |
| 143 state_ = kStopped; | 143 state_ = kStopped; |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 state_ = kStopped; | 146 state_ = kStopped; |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Tell the session to pause and then disconnect all clients. | 149 // Tell the session to pause and then disconnect all clients. |
| 150 if (session_.get()) { | 150 if (recorder_.get()) { |
| 151 session_->Pause(); | 151 recorder_->Pause(); |
| 152 session_->RemoveAllConnections(); | 152 recorder_->RemoveAllConnections(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Disconnect the client. | 155 // Disconnect the client. |
| 156 if (connection_) { | 156 if (connection_) { |
| 157 connection_->Disconnect(); | 157 connection_->Disconnect(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Stop the heartbeat sender. | 160 // Stop the heartbeat sender. |
| 161 if (heartbeat_sender_) { | 161 if (heartbeat_sender_) { |
| 162 heartbeat_sender_->Stop(); | 162 heartbeat_sender_->Stop(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 177 if (shutdown_task_.get()) { | 177 if (shutdown_task_.get()) { |
| 178 shutdown_task_->Run(); | 178 shutdown_task_->Run(); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 // This method is called when a client connects. | 182 // This method is called when a client connects. |
| 183 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) { | 183 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) { |
| 184 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 184 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
| 185 | 185 |
| 186 // Create a new RecordSession if there was none. | 186 // Create a new RecordSession if there was none. |
| 187 if (!session_.get()) { | 187 if (!recorder_.get()) { |
| 188 // Then we create a SessionManager passing the message loops that | 188 // Then we create a ScreenRecorder passing the message loops that |
| 189 // it should run on. | 189 // it should run on. |
| 190 DCHECK(capturer_.get()); | 190 DCHECK(capturer_.get()); |
| 191 | 191 |
| 192 Encoder* encoder = CreateEncoder(connection->session()->config()); | 192 Encoder* encoder = CreateEncoder(connection->session()->config()); |
| 193 | 193 |
| 194 session_ = new SessionManager(context_->main_message_loop(), | 194 recorder_ = new ScreenRecorder(context_->main_message_loop(), |
| 195 context_->encode_message_loop(), | 195 context_->encode_message_loop(), |
| 196 context_->network_message_loop(), | 196 context_->network_message_loop(), |
| 197 capturer_.release(), | 197 capturer_.release(), |
| 198 encoder); | 198 encoder); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Immediately add the connection and start the session. | 201 // Immediately add the connection and start the session. |
| 202 session_->AddConnection(connection); | 202 recorder_->AddConnection(connection); |
| 203 session_->Start(); | 203 recorder_->Start(); |
| 204 VLOG(1) << "Session manager started"; | 204 VLOG(1) << "Session manager started"; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { | 207 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { |
| 208 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 208 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
| 209 | 209 |
| 210 // Remove the connection from the session manager and pause the session. | 210 // Remove the connection from the session manager and pause the session. |
| 211 // TODO(hclam): Pause only if the last connection disconnected. | 211 // TODO(hclam): Pause only if the last connection disconnected. |
| 212 if (session_.get()) { | 212 if (recorder_.get()) { |
| 213 session_->RemoveConnection(connection); | 213 recorder_->RemoveConnection(connection); |
| 214 session_->Pause(); | 214 recorder_->Pause(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 // Close the connection to connection just to be safe. | 217 // Close the connection to connection just to be safe. |
| 218 connection->Disconnect(); | 218 connection->Disconnect(); |
| 219 | 219 |
| 220 // Also remove reference to ConnectionToClient from this object. | 220 // Also remove reference to ConnectionToClient from this object. |
| 221 connection_ = NULL; | 221 connection_ = NULL; |
| 222 } | 222 } |
| 223 | 223 |
| 224 //////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////// |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 #if !defined(ARCH_CPU_ARM_FAMILY) | 339 #if !defined(ARCH_CPU_ARM_FAMILY) |
| 340 else if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) { | 340 else if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) { |
| 341 return new remoting::EncoderVp8(); | 341 return new remoting::EncoderVp8(); |
| 342 } | 342 } |
| 343 #endif | 343 #endif |
| 344 | 344 |
| 345 return NULL; | 345 return NULL; |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace remoting | 348 } // namespace remoting |
| OLD | NEW |