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 #include "content/browser/renderer_host/media/video_capture_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
22 #include "gpu/command_buffer/common/mailbox_holder.h" | 22 #include "gpu/command_buffer/common/mailbox_holder.h" |
23 #include "media/base/video_frame.h" | 23 #include "media/base/video_frame.h" |
24 | 24 |
25 #if !defined(OS_ANDROID) | 25 #if !defined(OS_ANDROID) |
26 #include "content/browser/compositor/image_transport_factory.h" | 26 #include "content/browser/compositor/image_transport_factory.h" |
27 #endif | 27 #endif |
28 | 28 |
29 using media::VideoCaptureFormat; | 29 using media::VideoCaptureFormat; |
30 using media::VideoFrame; | 30 using media::VideoFrame; |
| 31 using media::VideoFrameMetadata; |
31 | 32 |
32 namespace content { | 33 namespace content { |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 static const int kInfiniteRatio = 99999; | 37 static const int kInfiniteRatio = 99999; |
37 | 38 |
38 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | 39 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ |
39 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | 40 UMA_HISTOGRAM_SPARSE_SLOWLY( \ |
40 name, \ | 41 name, \ |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (client) { | 228 if (client) { |
228 client->session_closed = true; | 229 client->session_closed = true; |
229 client->event_handler->OnEnded(client->controller_id); | 230 client->event_handler->OnEnded(client->controller_id); |
230 } | 231 } |
231 } | 232 } |
232 | 233 |
233 void VideoCaptureController::ReturnBuffer( | 234 void VideoCaptureController::ReturnBuffer( |
234 VideoCaptureControllerID id, | 235 VideoCaptureControllerID id, |
235 VideoCaptureControllerEventHandler* event_handler, | 236 VideoCaptureControllerEventHandler* event_handler, |
236 int buffer_id, | 237 int buffer_id, |
237 uint32 sync_point) { | 238 uint32 sync_point, |
| 239 double consumer_resource_utilization) { |
238 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 240 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
239 | 241 |
240 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 242 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
241 | 243 |
242 // If this buffer is not held by this client, or this client doesn't exist | 244 // If this buffer is not held by this client, or this client doesn't exist |
243 // in controller, do nothing. | 245 // in controller, do nothing. |
244 ControllerClient::ActiveBufferMap::iterator iter; | 246 ControllerClient::ActiveBufferMap::iterator iter; |
245 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 247 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
246 client->active_buffers.end()) { | 248 client->active_buffers.end()) { |
247 NOTREACHED(); | 249 NOTREACHED(); |
248 return; | 250 return; |
249 } | 251 } |
| 252 |
| 253 // Set the RESOURCE_UTILIZATION to the maximum of those provided by each |
| 254 // consumer (via separate calls to this method that refer to the same |
| 255 // VideoFrame). The producer of this VideoFrame may check this value, after |
| 256 // all consumer holds are relinquished, to make quality versus performance |
| 257 // trade-off decisions. |
250 scoped_refptr<VideoFrame> frame = iter->second; | 258 scoped_refptr<VideoFrame> frame = iter->second; |
| 259 if (std::isfinite(consumer_resource_utilization) && |
| 260 consumer_resource_utilization >= 0.0) { |
| 261 double resource_utilization = -1.0; |
| 262 if (frame->metadata()->GetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 263 &resource_utilization)) { |
| 264 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 265 std::max(consumer_resource_utilization, |
| 266 resource_utilization)); |
| 267 } else { |
| 268 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 269 consumer_resource_utilization); |
| 270 } |
| 271 } |
| 272 |
251 client->active_buffers.erase(iter); | 273 client->active_buffers.erase(iter); |
252 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 274 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
253 | 275 |
254 #if defined(OS_ANDROID) | 276 #if defined(OS_ANDROID) |
255 DCHECK_EQ(0u, sync_point); | 277 DCHECK_EQ(0u, sync_point); |
256 #endif | 278 #endif |
257 if (sync_point) | 279 if (sync_point) |
258 BrowserThread::PostTask(BrowserThread::UI, | 280 BrowserThread::PostTask(BrowserThread::UI, |
259 FROM_HERE, | 281 FROM_HERE, |
260 base::Bind(&ReturnVideoFrame, frame, sync_point)); | 282 base::Bind(&ReturnVideoFrame, frame, sync_point)); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 435 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
414 int active_client_count = 0; | 436 int active_client_count = 0; |
415 for (ControllerClient* client : controller_clients_) { | 437 for (ControllerClient* client : controller_clients_) { |
416 if (!client->paused) | 438 if (!client->paused) |
417 ++active_client_count; | 439 ++active_client_count; |
418 } | 440 } |
419 return active_client_count; | 441 return active_client_count; |
420 } | 442 } |
421 | 443 |
422 } // namespace content | 444 } // namespace content |
OLD | NEW |