| 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_stress_level) { |
| 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 STRESS_LEVEL to the maximum of those provided by each consumer. A |
| 254 // producer of the VideoFrame may check this value to make quality versus |
| 255 // performance trade-off decisions. |
| 250 scoped_refptr<VideoFrame> frame = iter->second; | 256 scoped_refptr<VideoFrame> frame = iter->second; |
| 257 if (std::isfinite(consumer_stress_level) && consumer_stress_level >= 0.0) { |
| 258 double stress_level = -1.0; |
| 259 if (frame->metadata()->GetDouble(VideoFrameMetadata::STRESS_LEVEL, |
| 260 &stress_level)) { |
| 261 frame->metadata()->SetDouble(VideoFrameMetadata::STRESS_LEVEL, |
| 262 std::max(consumer_stress_level, |
| 263 stress_level)); |
| 264 } else { |
| 265 frame->metadata()->SetDouble(VideoFrameMetadata::STRESS_LEVEL, |
| 266 consumer_stress_level); |
| 267 } |
| 268 } |
| 269 |
| 251 client->active_buffers.erase(iter); | 270 client->active_buffers.erase(iter); |
| 252 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 271 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 253 | 272 |
| 254 #if defined(OS_ANDROID) | 273 #if defined(OS_ANDROID) |
| 255 DCHECK_EQ(0u, sync_point); | 274 DCHECK_EQ(0u, sync_point); |
| 256 #endif | 275 #endif |
| 257 if (sync_point) | 276 if (sync_point) |
| 258 BrowserThread::PostTask(BrowserThread::UI, | 277 BrowserThread::PostTask(BrowserThread::UI, |
| 259 FROM_HERE, | 278 FROM_HERE, |
| 260 base::Bind(&ReturnVideoFrame, frame, sync_point)); | 279 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); | 432 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 414 int active_client_count = 0; | 433 int active_client_count = 0; |
| 415 for (ControllerClient* client : controller_clients_) { | 434 for (ControllerClient* client : controller_clients_) { |
| 416 if (!client->paused) | 435 if (!client->paused) |
| 417 ++active_client_count; | 436 ++active_client_count; |
| 418 } | 437 } |
| 419 return active_client_count; | 438 return active_client_count; |
| 420 } | 439 } |
| 421 | 440 |
| 422 } // namespace content | 441 } // namespace content |
| OLD | NEW |