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 28 matching lines...) Expand all Loading... |
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 SyncPointClientImpl : public VideoFrame::SyncPointClient { |
45 public: | 45 public: |
46 explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {} | 46 explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {} |
47 ~SyncPointClientImpl() override {} | 47 ~SyncPointClientImpl() 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 WaitSyncPoint(uint32 sync_point, |
50 gl_helper_->WaitSyncPoint(sync_point); | 50 const gpu::SyncToken& sync_token) override { |
| 51 gl_helper_->WaitSyncPoint(sync_point, sync_token); |
51 } | 52 } |
52 | 53 |
53 private: | 54 private: |
54 GLHelper* gl_helper_; | 55 GLHelper* gl_helper_; |
55 }; | 56 }; |
56 | 57 |
57 void ReturnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | 58 void ReturnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, |
58 uint32 sync_point) { | 59 uint32 sync_point, |
| 60 const gpu::SyncToken& sync_token) { |
59 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
60 #if defined(OS_ANDROID) | 62 #if defined(OS_ANDROID) |
61 NOTREACHED(); | 63 NOTREACHED(); |
62 #else | 64 #else |
63 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 65 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
64 // UpdateReleaseSyncPoint() creates a new sync_point using |gl_helper|, so | 66 // UpdateReleaseSyncPoint() creates a new sync_point using |gl_helper|, so |
65 // wait the given |sync_point| using |gl_helper|. | 67 // wait the given |sync_point| using |gl_helper|. |
66 if (gl_helper) { | 68 if (gl_helper) { |
67 gl_helper->WaitSyncPoint(sync_point); | 69 gl_helper->WaitSyncPoint(sync_point, sync_token); |
68 SyncPointClientImpl client(gl_helper); | 70 SyncPointClientImpl client(gl_helper); |
69 video_frame->UpdateReleaseSyncPoint(&client); | 71 video_frame->UpdateReleaseSyncPoint(&client); |
70 } | 72 } |
71 #endif | 73 #endif |
72 } | 74 } |
73 | 75 |
74 } // anonymous namespace | 76 } // anonymous namespace |
75 | 77 |
76 struct VideoCaptureController::ControllerClient { | 78 struct VideoCaptureController::ControllerClient { |
77 ControllerClient(VideoCaptureControllerID id, | 79 ControllerClient(VideoCaptureControllerID id, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 client->session_closed = true; | 249 client->session_closed = true; |
248 client->event_handler->OnEnded(client->controller_id); | 250 client->event_handler->OnEnded(client->controller_id); |
249 } | 251 } |
250 } | 252 } |
251 | 253 |
252 void VideoCaptureController::ReturnBuffer( | 254 void VideoCaptureController::ReturnBuffer( |
253 VideoCaptureControllerID id, | 255 VideoCaptureControllerID id, |
254 VideoCaptureControllerEventHandler* event_handler, | 256 VideoCaptureControllerEventHandler* event_handler, |
255 int buffer_id, | 257 int buffer_id, |
256 uint32 sync_point, | 258 uint32 sync_point, |
| 259 const gpu::SyncToken& sync_token, |
257 double consumer_resource_utilization) { | 260 double consumer_resource_utilization) { |
258 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 261 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
259 | 262 |
260 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 263 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
261 | 264 |
262 // If this buffer is not held by this client, or this client doesn't exist | 265 // If this buffer is not held by this client, or this client doesn't exist |
263 // in controller, do nothing. | 266 // in controller, do nothing. |
264 ControllerClient::ActiveBufferMap::iterator iter; | 267 ControllerClient::ActiveBufferMap::iterator iter; |
265 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 268 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
266 client->active_buffers.end()) { | 269 client->active_buffers.end()) { |
(...skipping 19 matching lines...) Expand all Loading... |
286 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, | 289 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, |
287 consumer_resource_utilization); | 290 consumer_resource_utilization); |
288 } | 291 } |
289 } | 292 } |
290 | 293 |
291 client->active_buffers.erase(iter); | 294 client->active_buffers.erase(iter); |
292 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 295 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
293 | 296 |
294 #if defined(OS_ANDROID) | 297 #if defined(OS_ANDROID) |
295 DCHECK_EQ(0u, sync_point); | 298 DCHECK_EQ(0u, sync_point); |
| 299 DCHECK_FALSE(sync_token.HasData()); |
296 #endif | 300 #endif |
297 if (sync_point) | 301 if (sync_point) |
298 BrowserThread::PostTask(BrowserThread::UI, | 302 BrowserThread::PostTask( |
299 FROM_HERE, | 303 BrowserThread::UI, FROM_HERE, |
300 base::Bind(&ReturnVideoFrame, frame, sync_point)); | 304 base::Bind(&ReturnVideoFrame, frame, sync_point, sync_token)); |
301 } | 305 } |
302 | 306 |
303 const media::VideoCaptureFormat& | 307 const media::VideoCaptureFormat& |
304 VideoCaptureController::GetVideoCaptureFormat() const { | 308 VideoCaptureController::GetVideoCaptureFormat() const { |
305 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 309 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
306 return video_capture_format_; | 310 return video_capture_format_; |
307 } | 311 } |
308 | 312 |
309 VideoCaptureController::~VideoCaptureController() { | 313 VideoCaptureController::~VideoCaptureController() { |
310 STLDeleteContainerPointers(controller_clients_.begin(), | 314 STLDeleteContainerPointers(controller_clients_.begin(), |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 468 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
465 int active_client_count = 0; | 469 int active_client_count = 0; |
466 for (ControllerClient* client : controller_clients_) { | 470 for (ControllerClient* client : controller_clients_) { |
467 if (!client->paused) | 471 if (!client->paused) |
468 ++active_client_count; | 472 ++active_client_count; |
469 } | 473 } |
470 return active_client_count; | 474 return active_client_count; |
471 } | 475 } |
472 | 476 |
473 } // namespace content | 477 } // namespace content |
OLD | NEW |