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/control.pb.h" | 14 #include "remoting/proto/control.pb.h" |
| 15 #include "remoting/proto/video.pb.h" |
15 #include "remoting/protocol/client_stub.h" | 16 #include "remoting/protocol/client_stub.h" |
16 #include "remoting/protocol/connection_to_client.h" | 17 #include "remoting/protocol/connection_to_client.h" |
17 #include "remoting/protocol/message_decoder.h" | 18 #include "remoting/protocol/message_decoder.h" |
18 #include "remoting/protocol/util.h" | 19 #include "remoting/protocol/util.h" |
19 | 20 |
20 using remoting::protocol::ConnectionToClient; | 21 using remoting::protocol::ConnectionToClient; |
21 | 22 |
22 namespace remoting { | 23 namespace remoting { |
23 | 24 |
24 // By default we capture 20 times a second. This number is obtained by | 25 // By default we capture 20 times a second. This number is obtained by |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (rate_ > 0) | 250 if (rate_ > 0) |
250 DoCapture(); | 251 DoCapture(); |
251 } | 252 } |
252 | 253 |
253 void SessionManager::DoGetInitInfo( | 254 void SessionManager::DoGetInitInfo( |
254 scoped_refptr<ConnectionToClient> connection) { | 255 scoped_refptr<ConnectionToClient> connection) { |
255 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 256 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
256 | 257 |
257 ScopedTracer tracer("init"); | 258 ScopedTracer tracer("init"); |
258 | 259 |
259 // Sends the init message to the connection. | 260 // Add the client to the list so it can receive update stream. |
260 network_loop_->PostTask( | |
261 FROM_HERE, | |
262 NewTracedMethod(this, &SessionManager::DoSendInit, connection, | |
263 capturer()->width(), capturer()->height())); | |
264 | |
265 // And then add the connection to the list so it can receive update stream. | |
266 // It is important we do so in such order or the connection will receive | |
267 // update stream before init message. | |
268 network_loop_->PostTask( | 261 network_loop_->PostTask( |
269 FROM_HERE, | 262 FROM_HERE, |
270 NewTracedMethod(this, &SessionManager::DoAddClient, connection)); | 263 NewTracedMethod(this, &SessionManager::DoAddClient, connection)); |
271 } | 264 } |
272 | 265 |
273 // Network thread -------------------------------------------------------------- | 266 // Network thread -------------------------------------------------------------- |
274 | 267 |
275 void SessionManager::DoStartRateControl() { | 268 void SessionManager::DoStartRateControl() { |
276 DCHECK_EQ(network_loop_, MessageLoop::current()); | 269 DCHECK_EQ(network_loop_, MessageLoop::current()); |
277 | 270 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 336 |
344 for (ConnectionToClientList::const_iterator i = connections_.begin(); | 337 for (ConnectionToClientList::const_iterator i = connections_.begin(); |
345 i < connections_.end(); ++i) { | 338 i < connections_.end(); ++i) { |
346 (*i)->SendVideoPacket(*packet); | 339 (*i)->SendVideoPacket(*packet); |
347 } | 340 } |
348 delete packet; | 341 delete packet; |
349 | 342 |
350 TraceContext::tracer()->PrintString("DoSendUpdate done"); | 343 TraceContext::tracer()->PrintString("DoSendUpdate done"); |
351 } | 344 } |
352 | 345 |
353 void SessionManager::DoSendInit(scoped_refptr<ConnectionToClient> connection, | |
354 int width, int height) { | |
355 DCHECK_EQ(network_loop_, MessageLoop::current()); | |
356 | |
357 // Sends the connection init information. | |
358 protocol::NotifyResolutionRequest* message = | |
359 new protocol::NotifyResolutionRequest(); | |
360 message->set_width(width); | |
361 message->set_height(height); | |
362 connection->client_stub()->NotifyResolution(message, | |
363 NewDeleteMessageTask(message)); | |
364 } | |
365 | |
366 void SessionManager::DoAddClient(scoped_refptr<ConnectionToClient> connection) { | 346 void SessionManager::DoAddClient(scoped_refptr<ConnectionToClient> connection) { |
367 DCHECK_EQ(network_loop_, MessageLoop::current()); | 347 DCHECK_EQ(network_loop_, MessageLoop::current()); |
368 | 348 |
369 // TODO(hclam): Force a full frame for next encode. | 349 // TODO(hclam): Force a full frame for next encode. |
370 connections_.push_back(connection); | 350 connections_.push_back(connection); |
371 } | 351 } |
372 | 352 |
373 void SessionManager::DoRemoveClient( | 353 void SessionManager::DoRemoveClient( |
374 scoped_refptr<ConnectionToClient> connection) { | 354 scoped_refptr<ConnectionToClient> connection) { |
375 DCHECK_EQ(network_loop_, MessageLoop::current()); | 355 DCHECK_EQ(network_loop_, MessageLoop::current()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 FROM_HERE, | 404 FROM_HERE, |
425 NewTracedMethod(this, &SessionManager::DoSendVideoPacket, packet)); | 405 NewTracedMethod(this, &SessionManager::DoSendVideoPacket, packet)); |
426 | 406 |
427 if (last) { | 407 if (last) { |
428 capture_loop_->PostTask( | 408 capture_loop_->PostTask( |
429 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); | 409 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); |
430 } | 410 } |
431 } | 411 } |
432 | 412 |
433 } // namespace remoting | 413 } // namespace remoting |
OLD | NEW |