| 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" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 315 } |
| 316 DCHECK_NE(new_rate, -1.0); | 316 DCHECK_NE(new_rate, -1.0); |
| 317 | 317 |
| 318 // Then set the rate. | 318 // Then set the rate. |
| 319 capture_loop_->PostTask( | 319 capture_loop_->PostTask( |
| 320 FROM_HERE, | 320 FROM_HERE, |
| 321 NewRunnableMethod(this, &SessionManager::DoSetRate, new_rate)); | 321 NewRunnableMethod(this, &SessionManager::DoSetRate, new_rate)); |
| 322 ScheduleNextRateControl(); | 322 ScheduleNextRateControl(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void SessionManager::DoSendUpdate(const UpdateStreamPacketHeader* header, | 325 void SessionManager::DoSendUpdate(HostMessage* message, |
| 326 const scoped_refptr<media::DataBuffer> data, | |
| 327 Encoder::EncodingState state) { | 326 Encoder::EncodingState state) { |
| 328 // Take ownership of header. | |
| 329 scoped_ptr<const UpdateStreamPacketHeader> header_owner(header); | |
| 330 DCHECK_EQ(network_loop_, MessageLoop::current()); | 327 DCHECK_EQ(network_loop_, MessageLoop::current()); |
| 331 | 328 |
| 329 // Create a data buffer in wire format from |message|. |
| 330 scoped_refptr<media::DataBuffer> data = |
| 331 ClientConnection::CreateWireFormatDataBuffer(message); |
| 332 |
| 332 for (ClientConnectionList::const_iterator i = clients_.begin(); | 333 for (ClientConnectionList::const_iterator i = clients_.begin(); |
| 333 i < clients_.end(); | 334 i < clients_.end(); ++i) { |
| 334 ++i) { | 335 // TODO(hclam): Merge BeginUpdateStreamMessage into |message|. |
| 335 if (state & Encoder::EncodingStarting) { | 336 if (state & Encoder::EncodingStarting) { |
| 336 (*i)->SendBeginUpdateStreamMessage(); | 337 (*i)->SendBeginUpdateStreamMessage(); |
| 337 } | 338 } |
| 338 | 339 |
| 339 (*i)->SendUpdateStreamPacketMessage(header, data); | 340 (*i)->SendUpdateStreamPacketMessage(data); |
| 340 | 341 |
| 341 if (state & Encoder::EncodingEnded) { | 342 // TODO(hclam): Merge EndUpdateStreamMessage into |message|. |
| 343 if (state & Encoder::EncodingEnded) |
| 342 (*i)->SendEndUpdateStreamMessage(); | 344 (*i)->SendEndUpdateStreamMessage(); |
| 343 } | |
| 344 } | 345 } |
| 345 } | 346 } |
| 346 | 347 |
| 347 void SessionManager::DoSendInit(scoped_refptr<ClientConnection> client, | 348 void SessionManager::DoSendInit(scoped_refptr<ClientConnection> client, |
| 348 int width, int height) { | 349 int width, int height) { |
| 349 DCHECK_EQ(network_loop_, MessageLoop::current()); | 350 DCHECK_EQ(network_loop_, MessageLoop::current()); |
| 350 | 351 |
| 351 // Sends the client init information. | 352 // Sends the client init information. |
| 352 client->SendInitClientMessage(width, height); | 353 client->SendInitClientMessage(width, height); |
| 353 } | 354 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 383 scoped_refptr<Capturer::CaptureData> capture_data) { | 384 scoped_refptr<Capturer::CaptureData> capture_data) { |
| 384 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 385 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
| 385 | 386 |
| 386 // TODO(hclam): Enable |force_refresh| if a new client was | 387 // TODO(hclam): Enable |force_refresh| if a new client was |
| 387 // added. | 388 // added. |
| 388 encoder_->Encode(capture_data, false, | 389 encoder_->Encode(capture_data, false, |
| 389 NewCallback(this, &SessionManager::EncodeDataAvailableTask)); | 390 NewCallback(this, &SessionManager::EncodeDataAvailableTask)); |
| 390 } | 391 } |
| 391 | 392 |
| 392 void SessionManager::EncodeDataAvailableTask( | 393 void SessionManager::EncodeDataAvailableTask( |
| 393 const UpdateStreamPacketHeader *header, | 394 HostMessage* message, Encoder::EncodingState state) { |
| 394 const scoped_refptr<media::DataBuffer>& data, | |
| 395 Encoder::EncodingState state) { | |
| 396 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 395 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
| 397 | 396 |
| 398 // Before a new encode task starts, notify clients a new update | 397 // Before a new encode task starts, notify clients a new update |
| 399 // stream is coming. | 398 // stream is coming. |
| 400 // Notify this will keep a reference to the DataBuffer in the | 399 // Notify this will keep a reference to the DataBuffer in the |
| 401 // task. The ownership will eventually pass to the ClientConnections. | 400 // task. The ownership will eventually pass to the ClientConnections. |
| 402 network_loop_->PostTask( | 401 network_loop_->PostTask( |
| 403 FROM_HERE, | 402 FROM_HERE, |
| 404 NewRunnableMethod(this, | 403 NewRunnableMethod(this, &SessionManager::DoSendUpdate, message, state)); |
| 405 &SessionManager::DoSendUpdate, | |
| 406 header, | |
| 407 data, | |
| 408 state)); | |
| 409 | 404 |
| 410 if (state & Encoder::EncodingEnded) { | 405 if (state & Encoder::EncodingEnded) { |
| 411 capture_loop_->PostTask( | 406 capture_loop_->PostTask( |
| 412 FROM_HERE, NewRunnableMethod(this, &SessionManager::DoFinishEncode)); | 407 FROM_HERE, NewRunnableMethod(this, &SessionManager::DoFinishEncode)); |
| 413 } | 408 } |
| 414 } | 409 } |
| 415 | 410 |
| 416 } // namespace remoting | 411 } // namespace remoting |
| OLD | NEW |