Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "components/display_compositor/gl_helper.h" | 19 #include "components/display_compositor/gl_helper.h" |
|
emircan
2016/11/09 22:14:38
We can remove this include now.
| |
| 20 #include "content/browser/renderer_host/media/media_stream_manager.h" | 20 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 21 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto ry_impl.h" | 21 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto ry_impl.h" |
| 22 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" | 22 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" |
| 23 #include "content/browser/renderer_host/media/video_capture_manager.h" | 23 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 26 #include "media/base/video_frame.h" | 26 #include "media/base/video_frame.h" |
| 27 #include "media/capture/video/video_capture_buffer_pool_impl.h" | 27 #include "media/capture/video/video_capture_buffer_pool_impl.h" |
| 28 #include "media/capture/video/video_capture_device_client.h" | 28 #include "media/capture/video/video_capture_device_client.h" |
| 29 | 29 |
| 30 #if !defined(OS_ANDROID) | 30 #if !defined(OS_ANDROID) |
| 31 #include "content/browser/compositor/image_transport_factory.h" | 31 #include "content/browser/compositor/image_transport_factory.h" |
|
emircan
2016/11/09 22:14:38
We can remove this include now.
| |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 using media::VideoCaptureFormat; | 34 using media::VideoCaptureFormat; |
| 35 using media::VideoFrame; | 35 using media::VideoFrame; |
| 36 using media::VideoFrameMetadata; | 36 using media::VideoFrameMetadata; |
| 37 | 37 |
| 38 namespace content { | 38 namespace content { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 static const int kInfiniteRatio = 99999; | 42 static const int kInfiniteRatio = 99999; |
| 43 | 43 |
| 44 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | 44 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ |
| 45 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | 45 UMA_HISTOGRAM_SPARSE_SLOWLY( \ |
| 46 name, \ | 46 name, \ |
| 47 (height) ? ((width) * 100) / (height) : kInfiniteRatio); | 47 (height) ? ((width) * 100) / (height) : kInfiniteRatio); |
| 48 | 48 |
| 49 class SyncTokenClientImpl : public VideoFrame::SyncTokenClient { | |
| 50 public: | |
| 51 explicit SyncTokenClientImpl(display_compositor::GLHelper* gl_helper) | |
| 52 : gl_helper_(gl_helper) {} | |
| 53 ~SyncTokenClientImpl() override {} | |
| 54 void GenerateSyncToken(gpu::SyncToken* sync_token) override { | |
| 55 gl_helper_->GenerateSyncToken(sync_token); | |
| 56 } | |
| 57 void WaitSyncToken(const gpu::SyncToken& sync_token) override { | |
| 58 gl_helper_->WaitSyncToken(sync_token); | |
| 59 } | |
| 60 | |
| 61 private: | |
| 62 display_compositor::GLHelper* gl_helper_; | |
| 63 }; | |
| 64 | |
| 65 void ReturnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | |
| 66 const gpu::SyncToken& sync_token) { | |
| 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 68 #if defined(OS_ANDROID) | |
| 69 NOTREACHED(); | |
| 70 #else | |
| 71 display_compositor::GLHelper* gl_helper = | |
| 72 ImageTransportFactory::GetInstance()->GetGLHelper(); | |
| 73 // UpdateReleaseSyncToken() creates a new sync_token using |gl_helper|, so | |
| 74 // wait the given |sync_token| using |gl_helper|. | |
| 75 if (gl_helper) { | |
| 76 gl_helper->WaitSyncToken(sync_token); | |
| 77 SyncTokenClientImpl client(gl_helper); | |
| 78 video_frame->UpdateReleaseSyncToken(&client); | |
| 79 } | |
| 80 #endif | |
| 81 } | |
| 82 | |
| 83 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder( | 49 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder( |
| 84 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) { | 50 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) { |
| 85 return base::MakeUnique<VideoCaptureGpuJpegDecoder>(decode_done_cb); | 51 return base::MakeUnique<VideoCaptureGpuJpegDecoder>(decode_done_cb); |
| 86 } | 52 } |
| 87 | 53 |
| 88 // Decorator for media::VideoFrameReceiver that forwards all incoming calls | 54 // Decorator for media::VideoFrameReceiver that forwards all incoming calls |
| 89 // to the Browser IO thread. | 55 // to the Browser IO thread. |
| 90 class VideoFrameReceiverOnIOThread : public media::VideoFrameReceiver { | 56 class VideoFrameReceiverOnIOThread : public media::VideoFrameReceiver { |
| 91 public: | 57 public: |
| 92 explicit VideoFrameReceiverOnIOThread( | 58 explicit VideoFrameReceiverOnIOThread( |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 if (client) { | 308 if (client) { |
| 343 client->session_closed = true; | 309 client->session_closed = true; |
| 344 client->event_handler->OnEnded(client->controller_id); | 310 client->event_handler->OnEnded(client->controller_id); |
| 345 } | 311 } |
| 346 } | 312 } |
| 347 | 313 |
| 348 void VideoCaptureController::ReturnBuffer( | 314 void VideoCaptureController::ReturnBuffer( |
| 349 VideoCaptureControllerID id, | 315 VideoCaptureControllerID id, |
| 350 VideoCaptureControllerEventHandler* event_handler, | 316 VideoCaptureControllerEventHandler* event_handler, |
| 351 int buffer_id, | 317 int buffer_id, |
| 352 const gpu::SyncToken& sync_token, | |
| 353 double consumer_resource_utilization) { | 318 double consumer_resource_utilization) { |
| 354 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 319 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 355 | 320 |
| 356 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 321 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 357 | 322 |
| 358 // If this buffer is not held by this client, or this client doesn't exist | 323 // If this buffer is not held by this client, or this client doesn't exist |
| 359 // in controller, do nothing. | 324 // in controller, do nothing. |
| 360 ControllerClient::ActiveBufferMap::iterator iter; | 325 ControllerClient::ActiveBufferMap::iterator iter; |
| 361 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 326 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
| 362 client->active_buffers.end()) { | 327 client->active_buffers.end()) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 379 std::max(consumer_resource_utilization, | 344 std::max(consumer_resource_utilization, |
| 380 resource_utilization)); | 345 resource_utilization)); |
| 381 } else { | 346 } else { |
| 382 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, | 347 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 383 consumer_resource_utilization); | 348 consumer_resource_utilization); |
| 384 } | 349 } |
| 385 } | 350 } |
| 386 | 351 |
| 387 client->active_buffers.erase(iter); | 352 client->active_buffers.erase(iter); |
| 388 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 353 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 389 | |
| 390 #if defined(OS_ANDROID) | |
| 391 DCHECK(!sync_token.HasData()); | |
| 392 #endif | |
| 393 if (sync_token.HasData()) | |
| 394 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 395 base::Bind(&ReturnVideoFrame, frame, sync_token)); | |
| 396 } | 354 } |
| 397 | 355 |
| 398 const media::VideoCaptureFormat& | 356 const media::VideoCaptureFormat& |
| 399 VideoCaptureController::GetVideoCaptureFormat() const { | 357 VideoCaptureController::GetVideoCaptureFormat() const { |
| 400 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 358 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 401 return video_capture_format_; | 359 return video_capture_format_; |
| 402 } | 360 } |
| 403 | 361 |
| 404 VideoCaptureController::~VideoCaptureController() { | 362 VideoCaptureController::~VideoCaptureController() { |
| 405 } | 363 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 int session_id, | 492 int session_id, |
| 535 const ControllerClients& clients) { | 493 const ControllerClients& clients) { |
| 536 for (const auto& client : clients) { | 494 for (const auto& client : clients) { |
| 537 if (client->session_id == session_id) | 495 if (client->session_id == session_id) |
| 538 return client.get(); | 496 return client.get(); |
| 539 } | 497 } |
| 540 return nullptr; | 498 return nullptr; |
| 541 } | 499 } |
| 542 | 500 |
| 543 } // namespace content | 501 } // namespace content |
| OLD | NEW |