| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 if (client) { | 260 if (client) { |
| 261 client->session_closed = true; | 261 client->session_closed = true; |
| 262 client->event_handler->OnEnded(client->controller_id); | 262 client->event_handler->OnEnded(client->controller_id); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 | 265 |
| 266 void VideoCaptureController::ReturnBuffer( | 266 void VideoCaptureController::ReturnBuffer( |
| 267 VideoCaptureControllerID id, | 267 VideoCaptureControllerID id, |
| 268 VideoCaptureControllerEventHandler* event_handler, | 268 VideoCaptureControllerEventHandler* event_handler, |
| 269 int buffer_id, | 269 int buffer_id, |
| 270 uint32 sync_point, | 270 const gpu::SyncToken& sync_token, |
| 271 double consumer_resource_utilization) { | 271 double consumer_resource_utilization) { |
| 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 273 | 273 |
| 274 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 274 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 275 | 275 |
| 276 // If this buffer is not held by this client, or this client doesn't exist | 276 // If this buffer is not held by this client, or this client doesn't exist |
| 277 // in controller, do nothing. | 277 // in controller, do nothing. |
| 278 ControllerClient::ActiveBufferMap::iterator iter; | 278 ControllerClient::ActiveBufferMap::iterator iter; |
| 279 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 279 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
| 280 client->active_buffers.end()) { | 280 client->active_buffers.end()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 299 } else { | 299 } else { |
| 300 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, | 300 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 301 consumer_resource_utilization); | 301 consumer_resource_utilization); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 client->active_buffers.erase(iter); | 305 client->active_buffers.erase(iter); |
| 306 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 306 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 307 | 307 |
| 308 #if defined(OS_ANDROID) | 308 #if defined(OS_ANDROID) |
| 309 DCHECK_EQ(0u, sync_point); | 309 DCHECK(!sync_token.HasData()); |
| 310 #endif | 310 #endif |
| 311 if (sync_point) | 311 if (sync_token.HasData()) |
| 312 BrowserThread::PostTask(BrowserThread::UI, | 312 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 313 FROM_HERE, | 313 base::Bind(&ReturnVideoFrame, frame, sync_token)); |
| 314 base::Bind(&ReturnVideoFrame, frame, sync_point)); | |
| 315 } | 314 } |
| 316 | 315 |
| 317 const media::VideoCaptureFormat& | 316 const media::VideoCaptureFormat& |
| 318 VideoCaptureController::GetVideoCaptureFormat() const { | 317 VideoCaptureController::GetVideoCaptureFormat() const { |
| 319 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 318 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 320 return video_capture_format_; | 319 return video_capture_format_; |
| 321 } | 320 } |
| 322 | 321 |
| 323 VideoCaptureController::~VideoCaptureController() { | 322 VideoCaptureController::~VideoCaptureController() { |
| 324 STLDeleteContainerPointers(controller_clients_.begin(), | 323 STLDeleteContainerPointers(controller_clients_.begin(), |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 int session_id, | 469 int session_id, |
| 471 const ControllerClients& clients) { | 470 const ControllerClients& clients) { |
| 472 for (auto client : clients) { | 471 for (auto client : clients) { |
| 473 if (client->session_id == session_id) | 472 if (client->session_id == session_id) |
| 474 return client; | 473 return client; |
| 475 } | 474 } |
| 476 return NULL; | 475 return NULL; |
| 477 } | 476 } |
| 478 | 477 |
| 479 } // namespace content | 478 } // namespace content |
| OLD | NEW |