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