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 "media/base/data_buffer.h" | 12 #include "media/base/data_buffer.h" |
| 13 #include "remoting/base/capture_data.h" |
13 #include "remoting/base/protocol_decoder.h" | 14 #include "remoting/base/protocol_decoder.h" |
14 #include "remoting/host/client_connection.h" | 15 #include "remoting/host/client_connection.h" |
15 #include "remoting/host/encoder.h" | |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 | 18 |
19 // By default we capture 20 times a second. This number is obtained by | 19 // By default we capture 20 times a second. This number is obtained by |
20 // experiment to provide good latency. | 20 // experiment to provide good latency. |
21 static const double kDefaultCaptureRate = 20.0; | 21 static const double kDefaultCaptureRate = 20.0; |
22 | 22 |
23 // Interval that we perform rate regulation. | 23 // Interval that we perform rate regulation. |
24 static const base::TimeDelta kRateControlInterval = | 24 static const base::TimeDelta kRateControlInterval = |
25 base::TimeDelta::FromSeconds(1); | 25 base::TimeDelta::FromSeconds(1); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 212 |
213 // TODO(dmaclach): make this not required on the Mac eventually. | 213 // TODO(dmaclach): make this not required on the Mac eventually. |
214 // Will require getting the X11client to work properly. Right now X11 expects | 214 // Will require getting the X11client to work properly. Right now X11 expects |
215 // full screens each pass. | 215 // full screens each pass. |
216 capturer_->InvalidateFullScreen(); | 216 capturer_->InvalidateFullScreen(); |
217 capturer_->CaptureInvalidRects( | 217 capturer_->CaptureInvalidRects( |
218 NewCallback(this, &SessionManager::CaptureDoneCallback)); | 218 NewCallback(this, &SessionManager::CaptureDoneCallback)); |
219 } | 219 } |
220 | 220 |
221 void SessionManager::CaptureDoneCallback( | 221 void SessionManager::CaptureDoneCallback( |
222 scoped_refptr<Capturer::CaptureData> capture_data) { | 222 scoped_refptr<CaptureData> capture_data) { |
223 // TODO(hclam): There is a bug if the capturer doesn't produce any dirty rects
. | 223 // TODO(hclam): There is a bug if the capturer doesn't produce any dirty rects
. |
224 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 224 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
225 encode_loop_->PostTask( | 225 encode_loop_->PostTask( |
226 FROM_HERE, | 226 FROM_HERE, |
227 NewRunnableMethod(this, &SessionManager::DoEncode, capture_data)); | 227 NewRunnableMethod(this, &SessionManager::DoEncode, capture_data)); |
228 } | 228 } |
229 | 229 |
230 void SessionManager::DoFinishEncode() { | 230 void SessionManager::DoFinishEncode() { |
231 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 231 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
232 | 232 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 void SessionManager::DoRemoveAllClients() { | 374 void SessionManager::DoRemoveAllClients() { |
375 DCHECK_EQ(network_loop_, MessageLoop::current()); | 375 DCHECK_EQ(network_loop_, MessageLoop::current()); |
376 | 376 |
377 // Clear the list of clients. | 377 // Clear the list of clients. |
378 clients_.clear(); | 378 clients_.clear(); |
379 } | 379 } |
380 | 380 |
381 // Encoder thread -------------------------------------------------------------- | 381 // Encoder thread -------------------------------------------------------------- |
382 | 382 |
383 void SessionManager::DoEncode( | 383 void SessionManager::DoEncode( |
384 scoped_refptr<Capturer::CaptureData> capture_data) { | 384 scoped_refptr<CaptureData> capture_data) { |
385 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 385 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
386 | 386 |
387 // TODO(hclam): Enable |force_refresh| if a new client was | 387 // TODO(hclam): Enable |force_refresh| if a new client was |
388 // added. | 388 // added. |
389 encoder_->Encode(capture_data, false, | 389 encoder_->Encode(capture_data, false, |
390 NewCallback(this, &SessionManager::EncodeDataAvailableTask)); | 390 NewCallback(this, &SessionManager::EncodeDataAvailableTask)); |
391 } | 391 } |
392 | 392 |
393 void SessionManager::EncodeDataAvailableTask( | 393 void SessionManager::EncodeDataAvailableTask( |
394 HostMessage* message, Encoder::EncodingState state) { | 394 HostMessage* message, Encoder::EncodingState state) { |
395 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 395 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
396 | 396 |
397 // Before a new encode task starts, notify clients a new update | 397 // Before a new encode task starts, notify clients a new update |
398 // stream is coming. | 398 // stream is coming. |
399 // Notify this will keep a reference to the DataBuffer in the | 399 // Notify this will keep a reference to the DataBuffer in the |
400 // task. The ownership will eventually pass to the ClientConnections. | 400 // task. The ownership will eventually pass to the ClientConnections. |
401 network_loop_->PostTask( | 401 network_loop_->PostTask( |
402 FROM_HERE, | 402 FROM_HERE, |
403 NewRunnableMethod(this, &SessionManager::DoSendUpdate, message, state)); | 403 NewRunnableMethod(this, &SessionManager::DoSendUpdate, message, state)); |
404 | 404 |
405 if (state & Encoder::EncodingEnded) { | 405 if (state & Encoder::EncodingEnded) { |
406 capture_loop_->PostTask( | 406 capture_loop_->PostTask( |
407 FROM_HERE, NewRunnableMethod(this, &SessionManager::DoFinishEncode)); | 407 FROM_HERE, NewRunnableMethod(this, &SessionManager::DoFinishEncode)); |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 } // namespace remoting | 411 } // namespace remoting |
OLD | NEW |