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 // Implementation notes: This needs to work on a variety of hardware | 5 // Implementation notes: This needs to work on a variety of hardware |
6 // configurations where the speed of the CPU and GPU greatly affect overall | 6 // configurations where the speed of the CPU and GPU greatly affect overall |
7 // performance. Spanning several threads, the process of capturing has been | 7 // performance. Spanning several threads, the process of capturing has been |
8 // split up into four conceptual stages: | 8 // split up into four conceptual stages: |
9 // | 9 // |
10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the consumer's | 10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the consumer's |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 | 1112 |
1113 oracle_->Start(); | 1113 oracle_->Start(); |
1114 } | 1114 } |
1115 | 1115 |
1116 // static | 1116 // static |
1117 void WebContentsVideoCaptureDevice::Impl::AssignCaptureMachine( | 1117 void WebContentsVideoCaptureDevice::Impl::AssignCaptureMachine( |
1118 base::WeakPtr<WebContentsVideoCaptureDevice::Impl> impl, | 1118 base::WeakPtr<WebContentsVideoCaptureDevice::Impl> impl, |
1119 scoped_ptr<CaptureMachine> capture_machine) { | 1119 scoped_ptr<CaptureMachine> capture_machine) { |
1120 DCHECK(!impl || impl->thread_checker_.CalledOnValidThread()); | 1120 DCHECK(!impl || impl->thread_checker_.CalledOnValidThread()); |
1121 | 1121 |
1122 if (!impl.get()) { | 1122 if (!impl) { |
1123 // If WCVD::Impl was destroyed before we got back on it's thread and | 1123 // If WCVD::Impl was destroyed before we got back on it's thread and |
1124 // capture_machine is not NULL, then we need to return to the UI thread to | 1124 // capture_machine is not NULL, then we need to return to the UI thread to |
1125 // safely cleanup the CaptureMachine. | 1125 // safely cleanup the CaptureMachine. |
1126 if (capture_machine.get()) { | 1126 if (capture_machine) { |
1127 BrowserThread::PostTask( | 1127 BrowserThread::PostTask( |
1128 BrowserThread::UI, FROM_HERE, base::Bind( | 1128 BrowserThread::UI, FROM_HERE, base::Bind( |
1129 &DeleteCaptureMachineOnUIThread, base::Passed(&capture_machine))); | 1129 &DeleteCaptureMachineOnUIThread, base::Passed(&capture_machine))); |
1130 return; | 1130 return; |
1131 } | 1131 } |
1132 } else if (!capture_machine.get()) { | 1132 } else if (!capture_machine) { |
1133 impl->Error(); | 1133 impl->Error(); |
1134 } else { | 1134 } else { |
1135 impl->capture_machine_ = capture_machine.Pass(); | 1135 impl->capture_machine_ = capture_machine.Pass(); |
1136 } | 1136 } |
1137 } | 1137 } |
1138 | 1138 |
1139 void WebContentsVideoCaptureDevice::Impl::Stop() { | 1139 void WebContentsVideoCaptureDevice::Impl::Stop() { |
1140 DCHECK(thread_checker_.CalledOnValidThread()); | 1140 DCHECK(thread_checker_.CalledOnValidThread()); |
1141 | 1141 |
1142 if (state_ != kCapturing) { | 1142 if (state_ != kCapturing) { |
(...skipping 17 matching lines...) Expand all Loading... |
1160 render_thread_.Stop(); | 1160 render_thread_.Stop(); |
1161 | 1161 |
1162 TransitionStateTo(kIdle); | 1162 TransitionStateTo(kIdle); |
1163 } | 1163 } |
1164 } | 1164 } |
1165 | 1165 |
1166 WebContentsVideoCaptureDevice::Impl::~Impl() { | 1166 WebContentsVideoCaptureDevice::Impl::~Impl() { |
1167 // There is still a capture pipeline running that is checking in with the | 1167 // There is still a capture pipeline running that is checking in with the |
1168 // oracle, and processing captures that are already started in flight. That | 1168 // oracle, and processing captures that are already started in flight. That |
1169 // pipeline must be shut down asynchronously, on the UI thread. | 1169 // pipeline must be shut down asynchronously, on the UI thread. |
1170 if (capture_machine_.get()) { | 1170 if (capture_machine_) { |
1171 // The task that is posted to the UI thread might not run if we are shutting | 1171 // The task that is posted to the UI thread might not run if we are shutting |
1172 // down, so we transfer ownership of CaptureMachine to the closure so that | 1172 // down, so we transfer ownership of CaptureMachine to the closure so that |
1173 // it is still cleaned up when the closure is deleted. | 1173 // it is still cleaned up when the closure is deleted. |
1174 BrowserThread::PostTask( | 1174 BrowserThread::PostTask( |
1175 BrowserThread::UI, FROM_HERE, base::Bind( | 1175 BrowserThread::UI, FROM_HERE, base::Bind( |
1176 &DeleteCaptureMachineOnUIThread, base::Passed(&capture_machine_))); | 1176 &DeleteCaptureMachineOnUIThread, base::Passed(&capture_machine_))); |
1177 } | 1177 } |
1178 | 1178 |
1179 DCHECK(!capture_machine_) << "Cleanup on UI thread did not happen."; | 1179 DCHECK(!capture_machine_) << "Cleanup on UI thread did not happen."; |
1180 DCHECK(!consumer_) << "Device not DeAllocated -- possible data race."; | 1180 DCHECK(!consumer_) << "Device not DeAllocated -- possible data race."; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 return false; | 1319 return false; |
1320 else | 1320 else |
1321 return true; | 1321 return true; |
1322 } | 1322 } |
1323 | 1323 |
1324 base::Time SmoothEventSampler::GetLastSampledEvent() { | 1324 base::Time SmoothEventSampler::GetLastSampledEvent() { |
1325 return last_sample_; | 1325 return last_sample_; |
1326 } | 1326 } |
1327 | 1327 |
1328 } // namespace content | 1328 } // namespace content |
OLD | NEW |