| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 321 } |
| 322 DCHECK_NE(new_rate, -1.0); | 322 DCHECK_NE(new_rate, -1.0); |
| 323 | 323 |
| 324 // Then set the rate. | 324 // Then set the rate. |
| 325 capture_loop_->PostTask( | 325 capture_loop_->PostTask( |
| 326 FROM_HERE, | 326 FROM_HERE, |
| 327 NewTracedMethod(this, &SessionManager::DoSetRate, new_rate)); | 327 NewTracedMethod(this, &SessionManager::DoSetRate, new_rate)); |
| 328 ScheduleNextRateControl(); | 328 ScheduleNextRateControl(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void SessionManager::DoSendVideoPacket(VideoPacket* packet) { | 331 void SessionManager::DoSendUpdate(ChromotingHostMessage* message, |
| 332 Encoder::EncodingState state) { |
| 332 DCHECK_EQ(network_loop_, MessageLoop::current()); | 333 DCHECK_EQ(network_loop_, MessageLoop::current()); |
| 333 | 334 |
| 334 TraceContext::tracer()->PrintString("DoSendUpdate"); | 335 TraceContext::tracer()->PrintString("DoSendUpdate"); |
| 335 | 336 |
| 336 for (ClientConnectionList::const_iterator i = clients_.begin(); | 337 for (ClientConnectionList::const_iterator i = clients_.begin(); |
| 337 i < clients_.end(); ++i) { | 338 i < clients_.end(); ++i) { |
| 338 (*i)->SendVideoPacket(*packet); | 339 (*i)->SendUpdateStreamPacketMessage(*message); |
| 339 } | 340 } |
| 340 delete packet; | 341 |
| 342 delete message; |
| 341 | 343 |
| 342 TraceContext::tracer()->PrintString("DoSendUpdate done"); | 344 TraceContext::tracer()->PrintString("DoSendUpdate done"); |
| 343 } | 345 } |
| 344 | 346 |
| 345 void SessionManager::DoSendInit(scoped_refptr<ClientConnection> client, | 347 void SessionManager::DoSendInit(scoped_refptr<ClientConnection> client, |
| 346 int width, int height) { | 348 int width, int height) { |
| 347 DCHECK_EQ(network_loop_, MessageLoop::current()); | 349 DCHECK_EQ(network_loop_, MessageLoop::current()); |
| 348 | 350 |
| 349 // Sends the client init information. | 351 // Sends the client init information. |
| 350 client->SendInitClientMessage(width, height); | 352 client->SendInitClientMessage(width, height); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 392 } |
| 391 | 393 |
| 392 // TODO(hclam): Enable |force_refresh| if a new client was | 394 // TODO(hclam): Enable |force_refresh| if a new client was |
| 393 // added. | 395 // added. |
| 394 TraceContext::tracer()->PrintString("Encode start"); | 396 TraceContext::tracer()->PrintString("Encode start"); |
| 395 encoder_->Encode(capture_data, false, | 397 encoder_->Encode(capture_data, false, |
| 396 NewCallback(this, &SessionManager::EncodeDataAvailableTask)); | 398 NewCallback(this, &SessionManager::EncodeDataAvailableTask)); |
| 397 TraceContext::tracer()->PrintString("Encode Done"); | 399 TraceContext::tracer()->PrintString("Encode Done"); |
| 398 } | 400 } |
| 399 | 401 |
| 400 void SessionManager::EncodeDataAvailableTask(VideoPacket* packet) { | 402 void SessionManager::EncodeDataAvailableTask( |
| 403 ChromotingHostMessage* message, Encoder::EncodingState state) { |
| 401 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 404 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
| 402 | 405 |
| 403 bool last = (packet->flags() & VideoPacket::LAST_PACKET) != 0; | |
| 404 | |
| 405 // Before a new encode task starts, notify clients a new update | 406 // Before a new encode task starts, notify clients a new update |
| 406 // stream is coming. | 407 // stream is coming. |
| 407 // Notify this will keep a reference to the DataBuffer in the | 408 // Notify this will keep a reference to the DataBuffer in the |
| 408 // task. The ownership will eventually pass to the ClientConnections. | 409 // task. The ownership will eventually pass to the ClientConnections. |
| 409 network_loop_->PostTask( | 410 network_loop_->PostTask( |
| 410 FROM_HERE, | 411 FROM_HERE, |
| 411 NewTracedMethod(this, &SessionManager::DoSendVideoPacket, packet)); | 412 NewTracedMethod(this, &SessionManager::DoSendUpdate, message, state)); |
| 412 | 413 |
| 413 if (last) { | 414 if (state & Encoder::EncodingEnded) { |
| 414 capture_loop_->PostTask( | 415 capture_loop_->PostTask( |
| 415 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); | 416 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); |
| 416 } | 417 } |
| 417 } | 418 } |
| 418 | 419 |
| 419 } // namespace remoting | 420 } // namespace remoting |
| OLD | NEW |