| 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 static const int kInfiniteRatio = 99999; | 37 static const int kInfiniteRatio = 99999; |
| 38 | 38 |
| 39 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | 39 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ |
| 40 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | 40 UMA_HISTOGRAM_SPARSE_SLOWLY( \ |
| 41 name, \ | 41 name, \ |
| 42 (height) ? ((width) * 100) / (height) : kInfiniteRatio); | 42 (height) ? ((width) * 100) / (height) : kInfiniteRatio); |
| 43 | 43 |
| 44 class SyncPointClientImpl : public VideoFrame::SyncPointClient { | 44 class SyncTokenClientImpl : public VideoFrame::SyncTokenClient { |
| 45 public: | 45 public: |
| 46 explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {} | 46 explicit SyncTokenClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {} |
| 47 ~SyncPointClientImpl() override {} | 47 ~SyncTokenClientImpl() override {} |
| 48 uint32 InsertSyncPoint() override { return gl_helper_->InsertSyncPoint(); } | 48 uint32 InsertSyncPoint() override { return gl_helper_->InsertSyncPoint(); } |
| 49 void WaitSyncPoint(uint32 sync_point) override { | 49 void WaitSyncToken(const gpu::SyncToken& sync_token) override { |
| 50 gl_helper_->WaitSyncPoint(sync_point); | 50 gl_helper_->WaitSyncToken(sync_token); |
| 51 } | 51 } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 GLHelper* gl_helper_; | 54 GLHelper* gl_helper_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 void ReturnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | 57 void ReturnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, |
| 58 uint32 sync_point) { | 58 const gpu::SyncToken& sync_token) { |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 60 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
| 61 NOTREACHED(); | 61 NOTREACHED(); |
| 62 #else | 62 #else |
| 63 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 63 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
| 64 // UpdateReleaseSyncPoint() creates a new sync_point using |gl_helper|, so | 64 // UpdateReleaseSyncToken() creates a new sync_token using |gl_helper|, so |
| 65 // wait the given |sync_point| using |gl_helper|. | 65 // wait the given |sync_token| using |gl_helper|. |
| 66 if (gl_helper) { | 66 if (gl_helper) { |
| 67 gl_helper->WaitSyncPoint(sync_point); | 67 gl_helper->WaitSyncToken(sync_token); |
| 68 SyncPointClientImpl client(gl_helper); | 68 SyncTokenClientImpl client(gl_helper); |
| 69 video_frame->UpdateReleaseSyncPoint(&client); | 69 video_frame->UpdateReleaseSyncToken(&client); |
| 70 } | 70 } |
| 71 #endif | 71 #endif |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // anonymous namespace | 74 } // anonymous namespace |
| 75 | 75 |
| 76 struct VideoCaptureController::ControllerClient { | 76 struct VideoCaptureController::ControllerClient { |
| 77 ControllerClient(VideoCaptureControllerID id, | 77 ControllerClient(VideoCaptureControllerID id, |
| 78 VideoCaptureControllerEventHandler* handler, | 78 VideoCaptureControllerEventHandler* handler, |
| 79 base::ProcessHandle render_process, | 79 base::ProcessHandle render_process, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 94 VideoCaptureControllerEventHandler* const event_handler; | 94 VideoCaptureControllerEventHandler* const event_handler; |
| 95 | 95 |
| 96 // Handle to the render process that will receive the capture buffers. | 96 // Handle to the render process that will receive the capture buffers. |
| 97 const base::ProcessHandle render_process_handle; | 97 const base::ProcessHandle render_process_handle; |
| 98 const media::VideoCaptureSessionId session_id; | 98 const media::VideoCaptureSessionId session_id; |
| 99 const media::VideoCaptureParams parameters; | 99 const media::VideoCaptureParams parameters; |
| 100 | 100 |
| 101 // Buffers that are currently known to this client. | 101 // Buffers that are currently known to this client. |
| 102 std::set<int> known_buffers; | 102 std::set<int> known_buffers; |
| 103 | 103 |
| 104 // Buffers currently held by this client, and syncpoint callback to call when | 104 // Buffers currently held by this client, and sync token callback to call when |
| 105 // they are returned from the client. | 105 // they are returned from the client. |
| 106 typedef std::map<int, scoped_refptr<VideoFrame>> ActiveBufferMap; | 106 typedef std::map<int, scoped_refptr<VideoFrame>> ActiveBufferMap; |
| 107 ActiveBufferMap active_buffers; | 107 ActiveBufferMap active_buffers; |
| 108 | 108 |
| 109 // State of capture session, controlled by VideoCaptureManager directly. This | 109 // State of capture session, controlled by VideoCaptureManager directly. This |
| 110 // transitions to true as soon as StopSession() occurs, at which point the | 110 // transitions to true as soon as StopSession() occurs, at which point the |
| 111 // client is sent an OnEnded() event. However, because the client retains a | 111 // client is sent an OnEnded() event. However, because the client retains a |
| 112 // VideoCaptureController* pointer, its ControllerClient entry lives on until | 112 // VideoCaptureController* pointer, its ControllerClient entry lives on until |
| 113 // it unregisters itself via RemoveClient(), which may happen asynchronously. | 113 // it unregisters itself via RemoveClient(), which may happen asynchronously. |
| 114 // | 114 // |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 if (client) { | 246 if (client) { |
| 247 client->session_closed = true; | 247 client->session_closed = true; |
| 248 client->event_handler->OnEnded(client->controller_id); | 248 client->event_handler->OnEnded(client->controller_id); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 void VideoCaptureController::ReturnBuffer( | 252 void VideoCaptureController::ReturnBuffer( |
| 253 VideoCaptureControllerID id, | 253 VideoCaptureControllerID id, |
| 254 VideoCaptureControllerEventHandler* event_handler, | 254 VideoCaptureControllerEventHandler* event_handler, |
| 255 int buffer_id, | 255 int buffer_id, |
| 256 uint32 sync_point, | 256 const gpu::SyncToken& sync_token, |
| 257 double consumer_resource_utilization) { | 257 double consumer_resource_utilization) { |
| 258 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 258 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 259 | 259 |
| 260 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 260 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 261 | 261 |
| 262 // If this buffer is not held by this client, or this client doesn't exist | 262 // If this buffer is not held by this client, or this client doesn't exist |
| 263 // in controller, do nothing. | 263 // in controller, do nothing. |
| 264 ControllerClient::ActiveBufferMap::iterator iter; | 264 ControllerClient::ActiveBufferMap::iterator iter; |
| 265 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 265 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
| 266 client->active_buffers.end()) { | 266 client->active_buffers.end()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 285 } else { | 285 } else { |
| 286 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, | 286 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 287 consumer_resource_utilization); | 287 consumer_resource_utilization); |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 | 290 |
| 291 client->active_buffers.erase(iter); | 291 client->active_buffers.erase(iter); |
| 292 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 292 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 293 | 293 |
| 294 #if defined(OS_ANDROID) | 294 #if defined(OS_ANDROID) |
| 295 DCHECK_EQ(0u, sync_point); | 295 DCHECK_FALSE(sync_token.HasData()); |
| 296 #endif | 296 #endif |
| 297 if (sync_point) | 297 if (sync_token.HasData()) |
| 298 BrowserThread::PostTask(BrowserThread::UI, | 298 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 299 FROM_HERE, | 299 base::Bind(&ReturnVideoFrame, frame, sync_token)); |
| 300 base::Bind(&ReturnVideoFrame, frame, sync_point)); | |
| 301 } | 300 } |
| 302 | 301 |
| 303 const media::VideoCaptureFormat& | 302 const media::VideoCaptureFormat& |
| 304 VideoCaptureController::GetVideoCaptureFormat() const { | 303 VideoCaptureController::GetVideoCaptureFormat() const { |
| 305 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 304 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 306 return video_capture_format_; | 305 return video_capture_format_; |
| 307 } | 306 } |
| 308 | 307 |
| 309 VideoCaptureController::~VideoCaptureController() { | 308 VideoCaptureController::~VideoCaptureController() { |
| 310 STLDeleteContainerPointers(controller_clients_.begin(), | 309 STLDeleteContainerPointers(controller_clients_.begin(), |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 463 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 465 int active_client_count = 0; | 464 int active_client_count = 0; |
| 466 for (ControllerClient* client : controller_clients_) { | 465 for (ControllerClient* client : controller_clients_) { |
| 467 if (!client->paused) | 466 if (!client->paused) |
| 468 ++active_client_count; | 467 ++active_client_count; |
| 469 } | 468 } |
| 470 return active_client_count; | 469 return active_client_count; |
| 471 } | 470 } |
| 472 | 471 |
| 473 } // namespace content | 472 } // namespace content |
| OLD | NEW |