| 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" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "content/browser/compositor/image_transport_factory.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_manager.h" | 16 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_manager.h" | 17 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 18 #include "content/common/gpu/client/gl_helper.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "gpu/command_buffer/common/mailbox_holder.h" | 20 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 19 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
| 20 #include "media/base/video_util.h" | 22 #include "media/base/video_util.h" |
| 21 #include "media/base/yuv_convert.h" | 23 #include "media/base/yuv_convert.h" |
| 22 #include "third_party/libyuv/include/libyuv.h" | 24 #include "third_party/libyuv/include/libyuv.h" |
| 23 | 25 |
| 24 using media::VideoCaptureFormat; | 26 using media::VideoCaptureFormat; |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 46 : Buffer(buffer_id, data, size), pool_(pool) { | 48 : Buffer(buffer_id, data, size), pool_(pool) { |
| 47 DCHECK(pool_); | 49 DCHECK(pool_); |
| 48 } | 50 } |
| 49 | 51 |
| 50 private: | 52 private: |
| 51 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); } | 53 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); } |
| 52 | 54 |
| 53 const scoped_refptr<VideoCaptureBufferPool> pool_; | 55 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 54 }; | 56 }; |
| 55 | 57 |
| 58 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { |
| 59 public: |
| 60 explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {} |
| 61 virtual ~SyncPointClientImpl() {} |
| 62 virtual uint32 InsertSyncPoint() { return gl_helper_->InsertSyncPoint(); } |
| 63 virtual void WaitSyncPoint(uint32 sync_point) { |
| 64 gl_helper_->WaitSyncPoint(sync_point); |
| 65 } |
| 66 |
| 67 private: |
| 68 GLHelper* gl_helper_; |
| 69 }; |
| 70 |
| 71 void ReturnVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
| 72 uint32 sync_point) { |
| 73 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 74 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
| 75 DCHECK(gl_helper); |
| 76 gl_helper->WaitSyncPoint(sync_point); |
| 77 SyncPointClientImpl client(gl_helper); |
| 78 video_frame->UpdateReleaseSyncPoint(&client); |
| 79 } |
| 80 |
| 56 } // anonymous namespace | 81 } // anonymous namespace |
| 57 | 82 |
| 58 struct VideoCaptureController::ControllerClient { | 83 struct VideoCaptureController::ControllerClient { |
| 59 ControllerClient(const VideoCaptureControllerID& id, | 84 ControllerClient(const VideoCaptureControllerID& id, |
| 60 VideoCaptureControllerEventHandler* handler, | 85 VideoCaptureControllerEventHandler* handler, |
| 61 base::ProcessHandle render_process, | 86 base::ProcessHandle render_process, |
| 62 media::VideoCaptureSessionId session_id, | 87 media::VideoCaptureSessionId session_id, |
| 63 const media::VideoCaptureParams& params) | 88 const media::VideoCaptureParams& params) |
| 64 : controller_id(id), | 89 : controller_id(id), |
| 65 event_handler(handler), | 90 event_handler(handler), |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (client) { | 267 if (client) { |
| 243 client->session_closed = true; | 268 client->session_closed = true; |
| 244 client->event_handler->OnEnded(client->controller_id); | 269 client->event_handler->OnEnded(client->controller_id); |
| 245 } | 270 } |
| 246 } | 271 } |
| 247 | 272 |
| 248 void VideoCaptureController::ReturnBuffer( | 273 void VideoCaptureController::ReturnBuffer( |
| 249 const VideoCaptureControllerID& id, | 274 const VideoCaptureControllerID& id, |
| 250 VideoCaptureControllerEventHandler* event_handler, | 275 VideoCaptureControllerEventHandler* event_handler, |
| 251 int buffer_id, | 276 int buffer_id, |
| 252 const std::vector<uint32>& sync_points) { | 277 uint32 sync_point) { |
| 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 254 | 279 |
| 255 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 280 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 256 | 281 |
| 257 // If this buffer is not held by this client, or this client doesn't exist | 282 // If this buffer is not held by this client, or this client doesn't exist |
| 258 // in controller, do nothing. | 283 // in controller, do nothing. |
| 259 ControllerClient::ActiveBufferMap::iterator iter; | 284 ControllerClient::ActiveBufferMap::iterator iter; |
| 260 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 285 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
| 261 client->active_buffers.end()) { | 286 client->active_buffers.end()) { |
| 262 NOTREACHED(); | 287 NOTREACHED(); |
| 263 return; | 288 return; |
| 264 } | 289 } |
| 265 scoped_refptr<media::VideoFrame> frame = iter->second; | 290 scoped_refptr<media::VideoFrame> frame = iter->second; |
| 266 client->active_buffers.erase(iter); | 291 client->active_buffers.erase(iter); |
| 292 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 267 | 293 |
| 268 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { | 294 if (sync_point) |
| 269 for (size_t i = 0; i < sync_points.size(); i++) | 295 BrowserThread::PostTask(BrowserThread::UI, |
| 270 frame->AppendReleaseSyncPoint(sync_points[i]); | 296 FROM_HERE, |
| 271 } | 297 base::Bind(&ReturnVideoFrame, frame, sync_point)); |
| 272 | |
| 273 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | |
| 274 } | 298 } |
| 275 | 299 |
| 276 const media::VideoCaptureFormat& | 300 const media::VideoCaptureFormat& |
| 277 VideoCaptureController::GetVideoCaptureFormat() const { | 301 VideoCaptureController::GetVideoCaptureFormat() const { |
| 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 302 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 279 return video_capture_format_; | 303 return video_capture_format_; |
| 280 } | 304 } |
| 281 | 305 |
| 282 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> | 306 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> |
| 283 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( | 307 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } | 665 } |
| 642 return NULL; | 666 return NULL; |
| 643 } | 667 } |
| 644 | 668 |
| 645 int VideoCaptureController::GetClientCount() { | 669 int VideoCaptureController::GetClientCount() { |
| 646 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 670 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 647 return controller_clients_.size(); | 671 return controller_clients_.size(); |
| 648 } | 672 } |
| 649 | 673 |
| 650 } // namespace content | 674 } // namespace content |
| OLD | NEW |