Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/capture/content/thread_safe_capture_oracle.h" | 5 #include "media/capture/content/thread_safe_capture_oracle.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 std::unique_ptr<VideoCaptureDevice::Client> client, | 38 std::unique_ptr<VideoCaptureDevice::Client> client, |
| 39 const VideoCaptureParams& params, | 39 const VideoCaptureParams& params, |
| 40 bool enable_auto_throttling) | 40 bool enable_auto_throttling) |
| 41 : client_(std::move(client)), | 41 : client_(std::move(client)), |
| 42 oracle_(base::TimeDelta::FromMicroseconds(static_cast<int64_t>( | 42 oracle_(base::TimeDelta::FromMicroseconds(static_cast<int64_t>( |
| 43 1000000.0 / params.requested_format.frame_rate + | 43 1000000.0 / params.requested_format.frame_rate + |
| 44 0.5 /* to round to nearest int */)), | 44 0.5 /* to round to nearest int */)), |
| 45 params.requested_format.frame_size, | 45 params.requested_format.frame_size, |
| 46 params.resolution_change_policy, | 46 params.resolution_change_policy, |
| 47 enable_auto_throttling), | 47 enable_auto_throttling), |
| 48 params_(params) {} | 48 params_(params), |
| 49 capture_(false) {} | |
| 49 | 50 |
| 50 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() { | 51 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() { |
| 51 } | 52 } |
| 52 | 53 |
| 53 bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( | 54 bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( |
| 54 VideoCaptureOracle::Event event, | 55 VideoCaptureOracle::Event event, |
| 55 const gfx::Rect& damage_rect, | 56 const gfx::Rect& damage_rect, |
| 56 base::TimeTicks event_time, | 57 base::TimeTicks event_time, |
| 57 scoped_refptr<VideoFrame>* storage, | 58 scoped_refptr<VideoFrame>* storage, |
| 58 CaptureFrameCallback* callback) { | 59 CaptureFrameCallback* callback) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 } | 181 } |
| 181 | 182 |
| 182 void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { | 183 void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { |
| 183 base::AutoLock guard(lock_); | 184 base::AutoLock guard(lock_); |
| 184 VLOG(1) << "Source size changed to " << source_size.ToString(); | 185 VLOG(1) << "Source size changed to " << source_size.ToString(); |
| 185 oracle_.SetSourceSize(source_size); | 186 oracle_.SetSourceSize(source_size); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void ThreadSafeCaptureOracle::Stop() { | 189 void ThreadSafeCaptureOracle::Stop() { |
| 189 base::AutoLock guard(lock_); | 190 base::AutoLock guard(lock_); |
| 191 capture_ = false; | |
| 190 client_.reset(); | 192 client_.reset(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 void ThreadSafeCaptureOracle::ReportError( | 195 void ThreadSafeCaptureOracle::ReportError( |
| 194 const tracked_objects::Location& from_here, | 196 const tracked_objects::Location& from_here, |
| 195 const std::string& reason) { | 197 const std::string& reason) { |
| 196 base::AutoLock guard(lock_); | 198 base::AutoLock guard(lock_); |
| 197 if (client_) | 199 if (client_) |
| 198 client_->OnError(from_here, reason); | 200 client_->OnError(from_here, reason); |
| 199 } | 201 } |
| 200 | 202 |
| 203 void ThreadSafeCaptureOracle::ReportStarted() { | |
| 204 base::AutoLock guard(lock_); | |
| 205 if (client_) | |
| 206 client_->OnStarted(); | |
| 207 capture_ = true; | |
| 208 } | |
| 209 | |
| 201 void ThreadSafeCaptureOracle::DidCaptureFrame( | 210 void ThreadSafeCaptureOracle::DidCaptureFrame( |
| 202 int frame_number, | 211 int frame_number, |
| 203 VideoCaptureDevice::Client::Buffer buffer, | 212 VideoCaptureDevice::Client::Buffer buffer, |
| 204 base::TimeTicks capture_begin_time, | 213 base::TimeTicks capture_begin_time, |
| 205 base::TimeDelta estimated_frame_duration, | 214 base::TimeDelta estimated_frame_duration, |
| 206 scoped_refptr<VideoFrame> frame, | 215 scoped_refptr<VideoFrame> frame, |
| 207 base::TimeTicks reference_time, | 216 base::TimeTicks reference_time, |
| 208 bool success) { | 217 bool success) { |
| 209 TRACE_EVENT_ASYNC_END2("gpu.capture", "Capture", buffer.id(), "success", | 218 TRACE_EVENT_ASYNC_END2("gpu.capture", "Capture", buffer.id(), "success", |
| 210 success, "timestamp", | 219 success, "timestamp", |
| 211 reference_time.ToInternalValue()); | 220 reference_time.ToInternalValue()); |
| 212 | 221 |
| 213 base::AutoLock guard(lock_); | 222 base::AutoLock guard(lock_); |
| 214 | 223 |
| 215 if (!oracle_.CompleteCapture(frame_number, success, &reference_time)) | 224 if (!oracle_.CompleteCapture(frame_number, success, &reference_time)) |
| 216 return; | 225 return; |
| 217 | 226 |
| 218 TRACE_EVENT_INSTANT0("gpu.capture", "CaptureSucceeded", | 227 TRACE_EVENT_INSTANT0("gpu.capture", "CaptureSucceeded", |
| 219 TRACE_EVENT_SCOPE_THREAD); | 228 TRACE_EVENT_SCOPE_THREAD); |
| 220 | 229 |
| 221 if (!client_) | 230 if (!client_ || !capture_) |
|
miu
2017/02/18 01:18:45
Dropping frames at this stage could break things (
braveyao
2017/02/22 18:06:44
Acknowledged.
| |
| 222 return; // Capture is stopped. | 231 return; // Capture is stopped. |
| 223 | 232 |
| 224 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, | 233 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, |
| 225 params_.requested_format.frame_rate); | 234 params_.requested_format.frame_rate); |
| 226 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_BEGIN_TIME, | 235 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_BEGIN_TIME, |
| 227 capture_begin_time); | 236 capture_begin_time); |
| 228 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_END_TIME, | 237 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_END_TIME, |
| 229 base::TimeTicks::Now()); | 238 base::TimeTicks::Now()); |
| 230 frame->metadata()->SetTimeDelta(VideoFrameMetadata::FRAME_DURATION, | 239 frame->metadata()->SetTimeDelta(VideoFrameMetadata::FRAME_DURATION, |
| 231 estimated_frame_duration); | 240 estimated_frame_duration); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 242 } | 251 } |
| 243 | 252 |
| 244 void ThreadSafeCaptureOracle::OnConsumerReportingUtilization( | 253 void ThreadSafeCaptureOracle::OnConsumerReportingUtilization( |
| 245 int frame_number, | 254 int frame_number, |
| 246 double utilization) { | 255 double utilization) { |
| 247 base::AutoLock guard(lock_); | 256 base::AutoLock guard(lock_); |
| 248 oracle_.RecordConsumerFeedback(frame_number, utilization); | 257 oracle_.RecordConsumerFeedback(frame_number, utilization); |
| 249 } | 258 } |
| 250 | 259 |
| 251 } // namespace media | 260 } // namespace media |
| OLD | NEW |