| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/video_scheduler.h" | 5 #include "remoting/host/video_scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void VideoScheduler::StopOnCaptureThread(const base::Closure& done_task) { | 169 void VideoScheduler::StopOnCaptureThread(const base::Closure& done_task) { |
| 170 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 170 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 171 | 171 |
| 172 // Stop |capturer_| and clear it to prevent pending tasks from using it. | 172 // Stop |capturer_| and clear it to prevent pending tasks from using it. |
| 173 capturer_->Stop(); | 173 capturer_->Stop(); |
| 174 capturer_ = NULL; | 174 capturer_ = NULL; |
| 175 | 175 |
| 176 // |capture_timer_| must be destroyed on the thread on which it is used. | 176 // |capture_timer_| must be destroyed on the thread on which it is used. |
| 177 capture_timer_.reset(); | 177 capture_timer_.reset(); |
| 178 | 178 |
| 179 // Activity on the encode thread will stop implicitly as a result of | 179 // Ensure that the encode thread is no longer processing capture data, |
| 180 // captures having stopped. | 180 // otherwise tearing down |capturer_| will crash it. See crbug.com/163641. |
| 181 network_task_runner_->PostTask(FROM_HERE, done_task); | 181 // TODO(wez): Make it safe to tear down capturer while buffers remain, and |
| 182 // remove this work-around. |
| 183 capture_task_runner_->PostTask(FROM_HERE, |
| 184 base::Bind(&VideoScheduler::StopOnEncodeThread, this, done_task)); |
| 182 } | 185 } |
| 183 | 186 |
| 184 void VideoScheduler::ScheduleNextCapture() { | 187 void VideoScheduler::ScheduleNextCapture() { |
| 185 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 188 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 186 | 189 |
| 187 capture_timer_->Start(FROM_HERE, | 190 capture_timer_->Start(FROM_HERE, |
| 188 scheduler_.NextCaptureDelay(), | 191 scheduler_.NextCaptureDelay(), |
| 189 this, | 192 this, |
| 190 &VideoScheduler::CaptureNextFrame); | 193 &VideoScheduler::CaptureNextFrame); |
| 191 } | 194 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if (last) { | 298 if (last) { |
| 296 scheduler_.RecordEncodeTime( | 299 scheduler_.RecordEncodeTime( |
| 297 base::TimeDelta::FromMilliseconds(packet->encode_time_ms())); | 300 base::TimeDelta::FromMilliseconds(packet->encode_time_ms())); |
| 298 } | 301 } |
| 299 | 302 |
| 300 network_task_runner_->PostTask( | 303 network_task_runner_->PostTask( |
| 301 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, | 304 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, |
| 302 base::Passed(&packet))); | 305 base::Passed(&packet))); |
| 303 } | 306 } |
| 304 | 307 |
| 308 void VideoScheduler::StopOnEncodeThread(const base::Closure& done_task) { |
| 309 DCHECK(encode_task_runner_->BelongsToCurrentThread()); |
| 310 |
| 311 // This is posted by StopOnCaptureThread, so we know that by the time we |
| 312 // process it there are no more encode tasks queued. |
| 313 network_task_runner_->PostTask(FROM_HERE, done_task); |
| 314 } |
| 315 |
| 305 } // namespace remoting | 316 } // namespace remoting |
| OLD | NEW |