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 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bits.h" | 11 #include "base/bits.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
16 #include "media/base/video_capture_types.h" | 17 #include "media/base/video_capture_types.h" |
17 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
(...skipping 10 matching lines...) Expand all Loading... |
28 // VideoCaptureOracle. This value takes into account the maximum number of | 29 // VideoCaptureOracle. This value takes into account the maximum number of |
29 // buffer pool buffers and a desired safety margin. | 30 // buffer pool buffers and a desired safety margin. |
30 const int kTargetMaxPoolUtilizationPercent = 60; | 31 const int kTargetMaxPoolUtilizationPercent = 60; |
31 | 32 |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( | 35 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( |
35 scoped_ptr<VideoCaptureDevice::Client> client, | 36 scoped_ptr<VideoCaptureDevice::Client> client, |
36 const VideoCaptureParams& params, | 37 const VideoCaptureParams& params, |
37 bool enable_auto_throttling) | 38 bool enable_auto_throttling) |
38 : client_(client.Pass()), | 39 : client_(std::move(client)), |
39 oracle_(base::TimeDelta::FromMicroseconds(static_cast<int64_t>( | 40 oracle_(base::TimeDelta::FromMicroseconds(static_cast<int64_t>( |
40 1000000.0 / params.requested_format.frame_rate + | 41 1000000.0 / params.requested_format.frame_rate + |
41 0.5 /* to round to nearest int */)), | 42 0.5 /* to round to nearest int */)), |
42 params.requested_format.frame_size, | 43 params.requested_format.frame_size, |
43 params.resolution_change_policy, | 44 params.resolution_change_policy, |
44 enable_auto_throttling), | 45 enable_auto_throttling), |
45 params_(params) {} | 46 params_(params) {} |
46 | 47 |
47 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() { | 48 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() { |
48 } | 49 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 capture_begin_time); | 179 capture_begin_time); |
179 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_END_TIME, | 180 frame->metadata()->SetTimeTicks(VideoFrameMetadata::CAPTURE_END_TIME, |
180 base::TimeTicks::Now()); | 181 base::TimeTicks::Now()); |
181 frame->metadata()->SetTimeDelta(VideoFrameMetadata::FRAME_DURATION, | 182 frame->metadata()->SetTimeDelta(VideoFrameMetadata::FRAME_DURATION, |
182 estimated_frame_duration); | 183 estimated_frame_duration); |
183 | 184 |
184 frame->AddDestructionObserver( | 185 frame->AddDestructionObserver( |
185 base::Bind(&ThreadSafeCaptureOracle::DidConsumeFrame, this, | 186 base::Bind(&ThreadSafeCaptureOracle::DidConsumeFrame, this, |
186 frame_number, frame->metadata())); | 187 frame_number, frame->metadata())); |
187 | 188 |
188 client_->OnIncomingCapturedVideoFrame(buffer.Pass(), frame, timestamp); | 189 client_->OnIncomingCapturedVideoFrame(std::move(buffer), frame, timestamp); |
189 } | 190 } |
190 } | 191 } |
191 | 192 |
192 void ThreadSafeCaptureOracle::DidConsumeFrame( | 193 void ThreadSafeCaptureOracle::DidConsumeFrame( |
193 int frame_number, | 194 int frame_number, |
194 const media::VideoFrameMetadata* metadata) { | 195 const media::VideoFrameMetadata* metadata) { |
195 // Note: This function may be called on any thread by the VideoFrame | 196 // Note: This function may be called on any thread by the VideoFrame |
196 // destructor. |metadata| is still valid for read-access at this point. | 197 // destructor. |metadata| is still valid for read-access at this point. |
197 double utilization = -1.0; | 198 double utilization = -1.0; |
198 if (metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 199 if (metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
199 &utilization)) { | 200 &utilization)) { |
200 base::AutoLock guard(lock_); | 201 base::AutoLock guard(lock_); |
201 oracle_.RecordConsumerFeedback(frame_number, utilization); | 202 oracle_.RecordConsumerFeedback(frame_number, utilization); |
202 } | 203 } |
203 } | 204 } |
204 | 205 |
205 } // namespace media | 206 } // namespace media |
OLD | NEW |