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/session_manager.h" | 5 #include "remoting/host/session_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
12 #include "remoting/base/capture_data.h" | 12 #include "remoting/base/capture_data.h" |
13 #include "remoting/base/tracer.h" | 13 #include "remoting/base/tracer.h" |
| 14 #include "remoting/proto/video.pb.h" |
14 #include "remoting/protocol/connection_to_client.h" | 15 #include "remoting/protocol/connection_to_client.h" |
15 #include "remoting/protocol/message_decoder.h" | 16 #include "remoting/protocol/message_decoder.h" |
16 | 17 |
17 using remoting::protocol::ConnectionToClient; | 18 using remoting::protocol::ConnectionToClient; |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
20 | 21 |
21 // By default we capture 20 times a second. This number is obtained by | 22 // By default we capture 20 times a second. This number is obtained by |
22 // experiment to provide good latency. | 23 // experiment to provide good latency. |
23 static const double kDefaultCaptureRate = 20.0; | 24 static const double kDefaultCaptureRate = 20.0; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 if (rate_ > 0) | 247 if (rate_ > 0) |
247 DoCapture(); | 248 DoCapture(); |
248 } | 249 } |
249 | 250 |
250 void SessionManager::DoGetInitInfo( | 251 void SessionManager::DoGetInitInfo( |
251 scoped_refptr<ConnectionToClient> connection) { | 252 scoped_refptr<ConnectionToClient> connection) { |
252 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 253 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
253 | 254 |
254 ScopedTracer tracer("init"); | 255 ScopedTracer tracer("init"); |
255 | 256 |
256 // Sends the init message to the connection. | 257 // Add the client to the list so it can receive update stream. |
257 network_loop_->PostTask( | |
258 FROM_HERE, | |
259 NewTracedMethod(this, &SessionManager::DoSendInit, connection, | |
260 capturer()->width(), capturer()->height())); | |
261 | |
262 // And then add the connection to the list so it can receive update stream. | |
263 // It is important we do so in such order or the connection will receive | |
264 // update stream before init message. | |
265 network_loop_->PostTask( | 258 network_loop_->PostTask( |
266 FROM_HERE, | 259 FROM_HERE, |
267 NewTracedMethod(this, &SessionManager::DoAddClient, connection)); | 260 NewTracedMethod(this, &SessionManager::DoAddClient, connection)); |
268 } | 261 } |
269 | 262 |
270 // Network thread -------------------------------------------------------------- | 263 // Network thread -------------------------------------------------------------- |
271 | 264 |
272 void SessionManager::DoStartRateControl() { | 265 void SessionManager::DoStartRateControl() { |
273 DCHECK_EQ(network_loop_, MessageLoop::current()); | 266 DCHECK_EQ(network_loop_, MessageLoop::current()); |
274 | 267 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 333 |
341 for (ConnectionToClientList::const_iterator i = connections_.begin(); | 334 for (ConnectionToClientList::const_iterator i = connections_.begin(); |
342 i < connections_.end(); ++i) { | 335 i < connections_.end(); ++i) { |
343 (*i)->SendVideoPacket(*packet); | 336 (*i)->SendVideoPacket(*packet); |
344 } | 337 } |
345 delete packet; | 338 delete packet; |
346 | 339 |
347 TraceContext::tracer()->PrintString("DoSendUpdate done"); | 340 TraceContext::tracer()->PrintString("DoSendUpdate done"); |
348 } | 341 } |
349 | 342 |
350 void SessionManager::DoSendInit(scoped_refptr<ConnectionToClient> connection, | |
351 int width, int height) { | |
352 DCHECK_EQ(network_loop_, MessageLoop::current()); | |
353 | |
354 // Sends the connection init information. | |
355 connection->SendInitClientMessage(width, height); | |
356 } | |
357 | |
358 void SessionManager::DoAddClient(scoped_refptr<ConnectionToClient> connection) { | 343 void SessionManager::DoAddClient(scoped_refptr<ConnectionToClient> connection) { |
359 DCHECK_EQ(network_loop_, MessageLoop::current()); | 344 DCHECK_EQ(network_loop_, MessageLoop::current()); |
360 | 345 |
361 // TODO(hclam): Force a full frame for next encode. | 346 // TODO(hclam): Force a full frame for next encode. |
362 connections_.push_back(connection); | 347 connections_.push_back(connection); |
363 } | 348 } |
364 | 349 |
365 void SessionManager::DoRemoveClient( | 350 void SessionManager::DoRemoveClient( |
366 scoped_refptr<ConnectionToClient> connection) { | 351 scoped_refptr<ConnectionToClient> connection) { |
367 DCHECK_EQ(network_loop_, MessageLoop::current()); | 352 DCHECK_EQ(network_loop_, MessageLoop::current()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 FROM_HERE, | 401 FROM_HERE, |
417 NewTracedMethod(this, &SessionManager::DoSendVideoPacket, packet)); | 402 NewTracedMethod(this, &SessionManager::DoSendVideoPacket, packet)); |
418 | 403 |
419 if (last) { | 404 if (last) { |
420 capture_loop_->PostTask( | 405 capture_loop_->PostTask( |
421 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); | 406 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); |
422 } | 407 } |
423 } | 408 } |
424 | 409 |
425 } // namespace remoting | 410 } // namespace remoting |
OLD | NEW |