| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 if (client_) | 195 if (client_) |
| 196 client_->OnError(from_here, reason); | 196 client_->OnError(from_here, reason); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void ThreadSafeCaptureOracle::DidCaptureFrame( | 199 void ThreadSafeCaptureOracle::DidCaptureFrame( |
| 200 int frame_number, | 200 int frame_number, |
| 201 std::unique_ptr<VideoCaptureDevice::Client::Buffer> buffer, | 201 std::unique_ptr<VideoCaptureDevice::Client::Buffer> buffer, |
| 202 base::TimeTicks capture_begin_time, | 202 base::TimeTicks capture_begin_time, |
| 203 base::TimeDelta estimated_frame_duration, | 203 base::TimeDelta estimated_frame_duration, |
| 204 const scoped_refptr<VideoFrame>& frame, | 204 const scoped_refptr<VideoFrame>& frame, |
| 205 base::TimeTicks timestamp, | 205 base::TimeTicks reference_time, |
| 206 bool success) { | 206 bool success) { |
| 207 TRACE_EVENT_ASYNC_END2("gpu.capture", "Capture", buffer.get(), "success", | 207 TRACE_EVENT_ASYNC_END2("gpu.capture", "Capture", buffer.get(), "success", |
| 208 success, "timestamp", timestamp.ToInternalValue()); | 208 success, "timestamp", |
| 209 reference_time.ToInternalValue()); |
| 209 | 210 |
| 210 base::AutoLock guard(lock_); | 211 base::AutoLock guard(lock_); |
| 211 | 212 |
| 212 if (oracle_.CompleteCapture(frame_number, success, ×tamp)) { | 213 if (oracle_.CompleteCapture(frame_number, success, &reference_time)) { |
| 213 TRACE_EVENT_INSTANT0("gpu.capture", "CaptureSucceeded", | 214 TRACE_EVENT_INSTANT0("gpu.capture", "CaptureSucceeded", |
| 214 TRACE_EVENT_SCOPE_THREAD); | 215 TRACE_EVENT_SCOPE_THREAD); |
| 215 | 216 |
| 216 if (!client_) | 217 if (!client_) |
| 217 return; // Capture is stopped. | 218 return; // Capture is stopped. |
| 218 | 219 |
| 219 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, | 220 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, |
| 220 params_.requested_format.frame_rate); | 221 params_.requested_format.frame_rate); |
| 221 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_BEGIN_TIME, | 222 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_BEGIN_TIME, |
| 222 capture_begin_time); | 223 capture_begin_time); |
| 223 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_END_TIME, | 224 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_END_TIME, |
| 224 base::TimeTicks::Now()); | 225 base::TimeTicks::Now()); |
| 225 frame->metadata()->SetTimeDelta(VideoFrameMetadata::FRAME_DURATION, | 226 frame->metadata()->SetTimeDelta(VideoFrameMetadata::FRAME_DURATION, |
| 226 estimated_frame_duration); | 227 estimated_frame_duration); |
| 228 frame->metadata()->SetTimeTicks(VideoFrameMetadata::REFERENCE_TIME, |
| 229 reference_time); |
| 227 | 230 |
| 228 frame->AddDestructionObserver( | 231 frame->AddDestructionObserver( |
| 229 base::Bind(&ThreadSafeCaptureOracle::DidConsumeFrame, this, | 232 base::Bind(&ThreadSafeCaptureOracle::DidConsumeFrame, this, |
| 230 frame_number, frame->metadata())); | 233 frame_number, frame->metadata())); |
| 231 | 234 |
| 232 client_->OnIncomingCapturedVideoFrame(std::move(buffer), frame, timestamp); | 235 client_->OnIncomingCapturedVideoFrame(std::move(buffer), frame); |
| 233 } | 236 } |
| 234 } | 237 } |
| 235 | 238 |
| 236 void ThreadSafeCaptureOracle::DidConsumeFrame( | 239 void ThreadSafeCaptureOracle::DidConsumeFrame( |
| 237 int frame_number, | 240 int frame_number, |
| 238 const media::VideoFrameMetadata* metadata) { | 241 const media::VideoFrameMetadata* metadata) { |
| 239 // Note: This function may be called on any thread by the VideoFrame | 242 // Note: This function may be called on any thread by the VideoFrame |
| 240 // destructor. |metadata| is still valid for read-access at this point. | 243 // destructor. |metadata| is still valid for read-access at this point. |
| 241 double utilization = -1.0; | 244 double utilization = -1.0; |
| 242 if (metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 245 if (metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 243 &utilization)) { | 246 &utilization)) { |
| 244 base::AutoLock guard(lock_); | 247 base::AutoLock guard(lock_); |
| 245 oracle_.RecordConsumerFeedback(frame_number, utilization); | 248 oracle_.RecordConsumerFeedback(frame_number, utilization); |
| 246 } | 249 } |
| 247 } | 250 } |
| 248 | 251 |
| 249 } // namespace media | 252 } // namespace media |
| OLD | NEW |