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, | 88 FROM_HERE, |
86 NewRunnableMethod(this, &ScreenRecorder::DoInvalidateFullScreen)); | 89 NewRunnableMethod(this, &ScreenRecorder::DoInvalidateFullScreen)); |
87 | |
88 // Add the client to the list so it can receive update stream. | |
89 network_loop_->PostTask( | |
90 FROM_HERE, | |
91 NewRunnableMethod(this, &ScreenRecorder::DoAddConnection, connection)); | |
92 } | 90 } |
93 | 91 |
94 void ScreenRecorder::RemoveConnection( | 92 void ScreenRecorder::RemoveConnection( |
95 scoped_refptr<ConnectionToClient> connection) { | 93 scoped_refptr<ConnectionToClient> connection) { |
96 network_loop_->PostTask( | 94 DCHECK(network_loop_->BelongsToCurrentThread()); |
97 FROM_HERE, | 95 |
98 NewRunnableMethod(this, &ScreenRecorder::DoRemoveClient, connection)); | 96 ConnectionToClientList::iterator it = |
| 97 std::find(connections_.begin(), connections_.end(), connection); |
| 98 if (it != connections_.end()) { |
| 99 connections_.erase(it); |
| 100 } |
99 } | 101 } |
100 | 102 |
101 void ScreenRecorder::RemoveAllConnections() { | 103 void ScreenRecorder::RemoveAllConnections() { |
102 network_loop_->PostTask( | 104 DCHECK(network_loop_->BelongsToCurrentThread()); |
103 FROM_HERE, | 105 connections_.clear(); |
104 NewRunnableMethod(this, &ScreenRecorder::DoRemoveAllClients)); | |
105 } | 106 } |
106 | 107 |
107 void ScreenRecorder::UpdateSequenceNumber(int64 sequence_number) { | 108 void ScreenRecorder::UpdateSequenceNumber(int64 sequence_number) { |
108 // Sequence number is used and written only on the capture thread. | 109 // Sequence number is used and written only on the capture thread. |
109 if (MessageLoop::current() != capture_loop_) { | 110 if (MessageLoop::current() != capture_loop_) { |
110 capture_loop_->PostTask( | 111 capture_loop_->PostTask( |
111 FROM_HERE, | 112 FROM_HERE, |
112 NewRunnableMethod(this, &ScreenRecorder::UpdateSequenceNumber, | 113 NewRunnableMethod(this, &ScreenRecorder::UpdateSequenceNumber, |
113 sequence_number)); | 114 sequence_number)); |
114 return; | 115 return; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 delete packet; | 271 delete packet; |
271 | 272 |
272 if (network_stopped_) | 273 if (network_stopped_) |
273 return; | 274 return; |
274 | 275 |
275 capture_loop_->PostTask( | 276 capture_loop_->PostTask( |
276 FROM_HERE, NewRunnableMethod(this, | 277 FROM_HERE, NewRunnableMethod(this, |
277 &ScreenRecorder::DoFinishOneRecording)); | 278 &ScreenRecorder::DoFinishOneRecording)); |
278 } | 279 } |
279 | 280 |
280 void ScreenRecorder::DoAddConnection( | |
281 scoped_refptr<ConnectionToClient> connection) { | |
282 DCHECK(network_loop_->BelongsToCurrentThread()); | |
283 | |
284 connections_.push_back(connection); | |
285 } | |
286 | |
287 void ScreenRecorder::DoRemoveClient( | |
288 scoped_refptr<ConnectionToClient> connection) { | |
289 DCHECK(network_loop_->BelongsToCurrentThread()); | |
290 | |
291 ConnectionToClientList::iterator it = | |
292 std::find(connections_.begin(), connections_.end(), connection); | |
293 if (it != connections_.end()) { | |
294 connections_.erase(it); | |
295 } | |
296 } | |
297 | |
298 void ScreenRecorder::DoRemoveAllClients() { | |
299 DCHECK(network_loop_->BelongsToCurrentThread()); | |
300 | |
301 // Clear the list of connections. | |
302 connections_.clear(); | |
303 } | |
304 | |
305 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { | 281 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { |
306 DCHECK(network_loop_->BelongsToCurrentThread()); | 282 DCHECK(network_loop_->BelongsToCurrentThread()); |
307 | 283 |
308 // There could be tasks on the network thread when this method is being | 284 // There could be tasks on the network thread when this method is being |
309 // executed. By setting the flag we'll not post anymore tasks from network | 285 // executed. By setting the flag we'll not post anymore tasks from network |
310 // thread. | 286 // thread. |
311 // | 287 // |
312 // After that a task is posted on encode thread to continue the stop | 288 // After that a task is posted on encode thread to continue the stop |
313 // sequence. | 289 // sequence. |
314 network_stopped_ = true; | 290 network_stopped_ = true; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 packet->set_encode_time_ms(encode_time_ms); | 345 packet->set_encode_time_ms(encode_time_ms); |
370 scheduler_.RecordEncodeTime(encode_time); | 346 scheduler_.RecordEncodeTime(encode_time); |
371 } | 347 } |
372 | 348 |
373 network_loop_->PostTask( | 349 network_loop_->PostTask( |
374 FROM_HERE, | 350 FROM_HERE, |
375 NewRunnableMethod(this, &ScreenRecorder::DoSendVideoPacket, packet)); | 351 NewRunnableMethod(this, &ScreenRecorder::DoSendVideoPacket, packet)); |
376 } | 352 } |
377 | 353 |
378 } // namespace remoting | 354 } // namespace remoting |
OLD | NEW |