Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: media/capture/content/thread_safe_capture_oracle.cc

Issue 2573223002: [Mojo Video Capture] Simplify media::VideoCaptureDevice::Client:Buffer to a struct (Closed)
Patch Set: mcasas comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 VideoCaptureOracle::Event event, 54 VideoCaptureOracle::Event event,
55 const gfx::Rect& damage_rect, 55 const gfx::Rect& damage_rect,
56 base::TimeTicks event_time, 56 base::TimeTicks event_time,
57 scoped_refptr<VideoFrame>* storage, 57 scoped_refptr<VideoFrame>* storage,
58 CaptureFrameCallback* callback) { 58 CaptureFrameCallback* callback) {
59 // Grab the current time before waiting to acquire the |lock_|. 59 // Grab the current time before waiting to acquire the |lock_|.
60 const base::TimeTicks capture_begin_time = base::TimeTicks::Now(); 60 const base::TimeTicks capture_begin_time = base::TimeTicks::Now();
61 61
62 gfx::Size visible_size; 62 gfx::Size visible_size;
63 gfx::Size coded_size; 63 gfx::Size coded_size;
64 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> output_buffer; 64 media::VideoCaptureDevice::Client::Buffer output_buffer;
65 double attenuated_utilization; 65 double attenuated_utilization;
66 int frame_number; 66 int frame_number;
67 base::TimeDelta estimated_frame_duration; 67 base::TimeDelta estimated_frame_duration;
68 { 68 {
69 base::AutoLock guard(lock_); 69 base::AutoLock guard(lock_);
70 70
71 if (!client_) 71 if (!client_)
72 return false; // Capture is stopped. 72 return false; // Capture is stopped.
73 73
74 if (!oracle_.ObserveEventAndDecideCapture(event, damage_rect, event_time)) { 74 if (!oracle_.ObserveEventAndDecideCapture(event, damage_rect, event_time)) {
(...skipping 11 matching lines...) Expand all
86 // TODO(miu): Clients should request exact padding, instead of this 86 // TODO(miu): Clients should request exact padding, instead of this
87 // memory-wasting hack to make frames that are compatible with all HW 87 // memory-wasting hack to make frames that are compatible with all HW
88 // encoders. http://crbug.com/555911 88 // encoders. http://crbug.com/555911
89 coded_size.SetSize(base::bits::Align(visible_size.width(), 16), 89 coded_size.SetSize(base::bits::Align(visible_size.width(), 16),
90 base::bits::Align(visible_size.height(), 16)); 90 base::bits::Align(visible_size.height(), 16));
91 91
92 if (event == VideoCaptureOracle::kPassiveRefreshRequest) { 92 if (event == VideoCaptureOracle::kPassiveRefreshRequest) {
93 output_buffer = client_->ResurrectLastOutputBuffer( 93 output_buffer = client_->ResurrectLastOutputBuffer(
94 coded_size, params_.requested_format.pixel_format, 94 coded_size, params_.requested_format.pixel_format,
95 params_.requested_format.pixel_storage, frame_number); 95 params_.requested_format.pixel_storage, frame_number);
96 if (!output_buffer) { 96 if (!output_buffer.is_valid()) {
97 TRACE_EVENT_INSTANT0("gpu.capture", "ResurrectionFailed", 97 TRACE_EVENT_INSTANT0("gpu.capture", "ResurrectionFailed",
98 TRACE_EVENT_SCOPE_THREAD); 98 TRACE_EVENT_SCOPE_THREAD);
99 return false; 99 return false;
100 } 100 }
101 } else { 101 } else {
102 output_buffer = client_->ReserveOutputBuffer( 102 output_buffer = client_->ReserveOutputBuffer(
103 coded_size, params_.requested_format.pixel_format, 103 coded_size, params_.requested_format.pixel_format,
104 params_.requested_format.pixel_storage, frame_number); 104 params_.requested_format.pixel_storage, frame_number);
105 } 105 }
106 106
107 // Get the current buffer pool utilization and attenuate it: The utilization 107 // Get the current buffer pool utilization and attenuate it: The utilization
108 // reported to the oracle is in terms of a maximum sustainable amount (not 108 // reported to the oracle is in terms of a maximum sustainable amount (not
109 // the absolute maximum). 109 // the absolute maximum).
110 attenuated_utilization = client_->GetBufferPoolUtilization() * 110 attenuated_utilization = client_->GetBufferPoolUtilization() *
111 (100.0 / kTargetMaxPoolUtilizationPercent); 111 (100.0 / kTargetMaxPoolUtilizationPercent);
112 112
113 if (!output_buffer) { 113 if (!output_buffer.is_valid()) {
114 TRACE_EVENT_INSTANT2( 114 TRACE_EVENT_INSTANT2(
115 "gpu.capture", "PipelineLimited", TRACE_EVENT_SCOPE_THREAD, "trigger", 115 "gpu.capture", "PipelineLimited", TRACE_EVENT_SCOPE_THREAD, "trigger",
116 VideoCaptureOracle::EventAsString(event), "atten_util_percent", 116 VideoCaptureOracle::EventAsString(event), "atten_util_percent",
117 base::saturated_cast<int>(attenuated_utilization * 100.0 + 0.5)); 117 base::saturated_cast<int>(attenuated_utilization * 100.0 + 0.5));
118 oracle_.RecordWillNotCapture(attenuated_utilization); 118 oracle_.RecordWillNotCapture(attenuated_utilization);
119 return false; 119 return false;
120 } 120 }
121 121
122 oracle_.RecordCapture(attenuated_utilization); 122 oracle_.RecordCapture(attenuated_utilization);
123 estimated_frame_duration = oracle_.estimated_frame_duration(); 123 estimated_frame_duration = oracle_.estimated_frame_duration();
124 } // End of critical section. 124 } // End of critical section.
125 125
126 if (attenuated_utilization >= 1.0) { 126 if (attenuated_utilization >= 1.0) {
127 TRACE_EVENT_INSTANT2( 127 TRACE_EVENT_INSTANT2(
128 "gpu.capture", "NearlyPipelineLimited", TRACE_EVENT_SCOPE_THREAD, 128 "gpu.capture", "NearlyPipelineLimited", TRACE_EVENT_SCOPE_THREAD,
129 "trigger", VideoCaptureOracle::EventAsString(event), 129 "trigger", VideoCaptureOracle::EventAsString(event),
130 "atten_util_percent", 130 "atten_util_percent",
131 base::saturated_cast<int>(attenuated_utilization * 100.0 + 0.5)); 131 base::saturated_cast<int>(attenuated_utilization * 100.0 + 0.5));
132 } 132 }
133 133
134 TRACE_EVENT_ASYNC_BEGIN2("gpu.capture", "Capture", output_buffer.get(), 134 TRACE_EVENT_ASYNC_BEGIN2("gpu.capture", "Capture", output_buffer.id(),
135 "frame_number", frame_number, "trigger", 135 "frame_number", frame_number, "trigger",
136 VideoCaptureOracle::EventAsString(event)); 136 VideoCaptureOracle::EventAsString(event));
137 137
138 auto output_buffer_access =
139 output_buffer.handle_provider()->GetHandleForInProcessAccess();
138 DCHECK_EQ(media::PIXEL_STORAGE_CPU, params_.requested_format.pixel_storage); 140 DCHECK_EQ(media::PIXEL_STORAGE_CPU, params_.requested_format.pixel_storage);
139 *storage = VideoFrame::WrapExternalSharedMemory( 141 *storage = VideoFrame::WrapExternalSharedMemory(
140 params_.requested_format.pixel_format, coded_size, 142 params_.requested_format.pixel_format, coded_size,
141 gfx::Rect(visible_size), visible_size, 143 gfx::Rect(visible_size), visible_size, output_buffer_access->data(),
142 static_cast<uint8_t*>(output_buffer->data()), 144 output_buffer_access->mapped_size(), base::SharedMemory::NULLHandle(), 0u,
143 output_buffer->mapped_size(), base::SharedMemory::NULLHandle(), 0u,
144 base::TimeDelta()); 145 base::TimeDelta());
145 // If creating the VideoFrame wrapper failed, call DidCaptureFrame() with 146 // If creating the VideoFrame wrapper failed, call DidCaptureFrame() with
146 // !success to execute the required post-capture steps (tracing, notification 147 // !success to execute the required post-capture steps (tracing, notification
147 // of failure to VideoCaptureOracle, etc.). 148 // of failure to VideoCaptureOracle, etc.).
148 if (!(*storage)) { 149 if (!(*storage)) {
149 DidCaptureFrame(frame_number, std::move(output_buffer), capture_begin_time, 150 DidCaptureFrame(frame_number, std::move(output_buffer), capture_begin_time,
150 estimated_frame_duration, *storage, event_time, false); 151 estimated_frame_duration, *storage, event_time, false);
151 return false; 152 return false;
152 } 153 }
153 154
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 void ThreadSafeCaptureOracle::ReportError( 193 void ThreadSafeCaptureOracle::ReportError(
193 const tracked_objects::Location& from_here, 194 const tracked_objects::Location& from_here,
194 const std::string& reason) { 195 const std::string& reason) {
195 base::AutoLock guard(lock_); 196 base::AutoLock guard(lock_);
196 if (client_) 197 if (client_)
197 client_->OnError(from_here, reason); 198 client_->OnError(from_here, reason);
198 } 199 }
199 200
200 void ThreadSafeCaptureOracle::DidCaptureFrame( 201 void ThreadSafeCaptureOracle::DidCaptureFrame(
201 int frame_number, 202 int frame_number,
202 std::unique_ptr<VideoCaptureDevice::Client::Buffer> buffer, 203 VideoCaptureDevice::Client::Buffer buffer,
203 base::TimeTicks capture_begin_time, 204 base::TimeTicks capture_begin_time,
204 base::TimeDelta estimated_frame_duration, 205 base::TimeDelta estimated_frame_duration,
205 scoped_refptr<VideoFrame> frame, 206 scoped_refptr<VideoFrame> frame,
206 base::TimeTicks reference_time, 207 base::TimeTicks reference_time,
207 bool success) { 208 bool success) {
208 TRACE_EVENT_ASYNC_END2("gpu.capture", "Capture", buffer.get(), "success", 209 TRACE_EVENT_ASYNC_END2("gpu.capture", "Capture", buffer.id(), "success",
209 success, "timestamp", 210 success, "timestamp",
210 reference_time.ToInternalValue()); 211 reference_time.ToInternalValue());
211 212
212 base::AutoLock guard(lock_); 213 base::AutoLock guard(lock_);
213 214
214 if (!oracle_.CompleteCapture(frame_number, success, &reference_time)) 215 if (!oracle_.CompleteCapture(frame_number, success, &reference_time))
215 return; 216 return;
216 217
217 TRACE_EVENT_INSTANT0("gpu.capture", "CaptureSucceeded", 218 TRACE_EVENT_INSTANT0("gpu.capture", "CaptureSucceeded",
218 TRACE_EVENT_SCOPE_THREAD); 219 TRACE_EVENT_SCOPE_THREAD);
(...skipping 22 matching lines...) Expand all
241 } 242 }
242 243
243 void ThreadSafeCaptureOracle::OnConsumerReportingUtilization( 244 void ThreadSafeCaptureOracle::OnConsumerReportingUtilization(
244 int frame_number, 245 int frame_number,
245 double utilization) { 246 double utilization) {
246 base::AutoLock guard(lock_); 247 base::AutoLock guard(lock_);
247 oracle_.RecordConsumerFeedback(frame_number, utilization); 248 oracle_.RecordConsumerFeedback(frame_number, utilization);
248 } 249 }
249 250
250 } // namespace media 251 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/content/thread_safe_capture_oracle.h ('k') | media/capture/video/fake_video_capture_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698