| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/screen_recorder.h" | 5 #include "remoting/host/screen_recorder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 capture_timer_.Stop(); | 75 capture_timer_.Stop(); |
| 76 is_recording_ = false; | 76 is_recording_ = false; |
| 77 | 77 |
| 78 network_loop_->PostTask(FROM_HERE, base::Bind( | 78 network_loop_->PostTask(FROM_HERE, base::Bind( |
| 79 &ScreenRecorder::DoStopOnNetworkThread, this, done_task)); | 79 &ScreenRecorder::DoStopOnNetworkThread, this, done_task)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ScreenRecorder::AddConnection( | 82 void ScreenRecorder::AddConnection( |
| 83 scoped_refptr<ConnectionToClient> connection) { | 83 scoped_refptr<ConnectionToClient> connection) { |
| 84 DCHECK(network_loop_->BelongsToCurrentThread()); |
| 85 connections_.push_back(connection); |
| 86 |
| 84 capture_loop_->PostTask( | 87 capture_loop_->PostTask( |
| 85 FROM_HERE, base::Bind(&ScreenRecorder::DoInvalidateFullScreen, this)); | 88 FROM_HERE, base::Bind(&ScreenRecorder::DoInvalidateFullScreen, this)); |
| 86 | |
| 87 // Add the client to the list so it can receive update stream. | |
| 88 network_loop_->PostTask( | |
| 89 FROM_HERE, base::Bind(&ScreenRecorder::DoAddConnection, | |
| 90 this, connection)); | |
| 91 } | 89 } |
| 92 | 90 |
| 93 void ScreenRecorder::RemoveConnection( | 91 void ScreenRecorder::RemoveConnection( |
| 94 scoped_refptr<ConnectionToClient> connection) { | 92 scoped_refptr<ConnectionToClient> connection) { |
| 95 network_loop_->PostTask( | 93 DCHECK(network_loop_->BelongsToCurrentThread()); |
| 96 FROM_HERE, base::Bind(&ScreenRecorder::DoRemoveClient, this, connection)); | 94 |
| 95 ConnectionToClientList::iterator it = |
| 96 std::find(connections_.begin(), connections_.end(), connection); |
| 97 if (it != connections_.end()) { |
| 98 connections_.erase(it); |
| 99 } |
| 97 } | 100 } |
| 98 | 101 |
| 99 void ScreenRecorder::RemoveAllConnections() { | 102 void ScreenRecorder::RemoveAllConnections() { |
| 100 network_loop_->PostTask( | 103 DCHECK(network_loop_->BelongsToCurrentThread()); |
| 101 FROM_HERE, base::Bind(&ScreenRecorder::DoRemoveAllClients, this)); | 104 connections_.clear(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void ScreenRecorder::UpdateSequenceNumber(int64 sequence_number) { | 107 void ScreenRecorder::UpdateSequenceNumber(int64 sequence_number) { |
| 105 // Sequence number is used and written only on the capture thread. | 108 // Sequence number is used and written only on the capture thread. |
| 106 if (MessageLoop::current() != capture_loop_) { | 109 if (MessageLoop::current() != capture_loop_) { |
| 107 capture_loop_->PostTask( | 110 capture_loop_->PostTask( |
| 108 FROM_HERE, base::Bind(&ScreenRecorder::UpdateSequenceNumber, | 111 FROM_HERE, base::Bind(&ScreenRecorder::UpdateSequenceNumber, |
| 109 this, sequence_number)); | 112 this, sequence_number)); |
| 110 return; | 113 return; |
| 111 } | 114 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 void ScreenRecorder::FrameSentCallback(VideoPacket* packet) { | 267 void ScreenRecorder::FrameSentCallback(VideoPacket* packet) { |
| 265 delete packet; | 268 delete packet; |
| 266 | 269 |
| 267 if (network_stopped_) | 270 if (network_stopped_) |
| 268 return; | 271 return; |
| 269 | 272 |
| 270 capture_loop_->PostTask( | 273 capture_loop_->PostTask( |
| 271 FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this)); | 274 FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this)); |
| 272 } | 275 } |
| 273 | 276 |
| 274 void ScreenRecorder::DoAddConnection( | |
| 275 scoped_refptr<ConnectionToClient> connection) { | |
| 276 DCHECK(network_loop_->BelongsToCurrentThread()); | |
| 277 | |
| 278 connections_.push_back(connection); | |
| 279 } | |
| 280 | |
| 281 void ScreenRecorder::DoRemoveClient( | |
| 282 scoped_refptr<ConnectionToClient> connection) { | |
| 283 DCHECK(network_loop_->BelongsToCurrentThread()); | |
| 284 | |
| 285 ConnectionToClientList::iterator it = | |
| 286 std::find(connections_.begin(), connections_.end(), connection); | |
| 287 if (it != connections_.end()) { | |
| 288 connections_.erase(it); | |
| 289 } | |
| 290 } | |
| 291 | |
| 292 void ScreenRecorder::DoRemoveAllClients() { | |
| 293 DCHECK(network_loop_->BelongsToCurrentThread()); | |
| 294 | |
| 295 // Clear the list of connections. | |
| 296 connections_.clear(); | |
| 297 } | |
| 298 | |
| 299 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { | 277 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { |
| 300 DCHECK(network_loop_->BelongsToCurrentThread()); | 278 DCHECK(network_loop_->BelongsToCurrentThread()); |
| 301 | 279 |
| 302 // There could be tasks on the network thread when this method is being | 280 // There could be tasks on the network thread when this method is being |
| 303 // executed. By setting the flag we'll not post anymore tasks from network | 281 // executed. By setting the flag we'll not post anymore tasks from network |
| 304 // thread. | 282 // thread. |
| 305 // | 283 // |
| 306 // After that a task is posted on encode thread to continue the stop | 284 // After that a task is posted on encode thread to continue the stop |
| 307 // sequence. | 285 // sequence. |
| 308 network_stopped_ = true; | 286 network_stopped_ = true; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 static_cast<int>(encode_time.InMilliseconds()); | 337 static_cast<int>(encode_time.InMilliseconds()); |
| 360 packet->set_encode_time_ms(encode_time_ms); | 338 packet->set_encode_time_ms(encode_time_ms); |
| 361 scheduler_.RecordEncodeTime(encode_time); | 339 scheduler_.RecordEncodeTime(encode_time); |
| 362 } | 340 } |
| 363 | 341 |
| 364 network_loop_->PostTask( | 342 network_loop_->PostTask( |
| 365 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, packet)); | 343 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, packet)); |
| 366 } | 344 } |
| 367 | 345 |
| 368 } // namespace remoting | 346 } // namespace remoting |
| OLD | NEW |