| 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/renderer_host/media/media_stream_manager.h" | 15 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_manager.h" | 16 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 17 #include "content/common/gpu/client/gl_helper.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "gpu/command_buffer/common/mailbox_holder.h" | 19 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 19 #include "media/base/video_frame.h" | 20 #include "media/base/video_frame.h" |
| 20 #include "media/base/video_util.h" | 21 #include "media/base/video_util.h" |
| 21 #include "media/base/yuv_convert.h" | 22 #include "media/base/yuv_convert.h" |
| 22 #include "third_party/libyuv/include/libyuv.h" | 23 #include "third_party/libyuv/include/libyuv.h" |
| 23 | 24 |
| 25 #if defined(OS_ANDROID) |
| 26 #include "content/browser/renderer_host/image_transport_factory_android.h" |
| 27 #else |
| 28 #include "content/browser/compositor/image_transport_factory.h" |
| 29 #endif |
| 30 |
| 24 using media::VideoCaptureFormat; | 31 using media::VideoCaptureFormat; |
| 25 | 32 |
| 26 namespace content { | 33 namespace content { |
| 27 | 34 |
| 28 namespace { | 35 namespace { |
| 29 | 36 |
| 30 static const int kInfiniteRatio = 99999; | 37 static const int kInfiniteRatio = 99999; |
| 31 | 38 |
| 32 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | 39 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ |
| 33 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | 40 UMA_HISTOGRAM_SPARSE_SLOWLY( \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 46 : Buffer(buffer_id, data, size), pool_(pool) { | 53 : Buffer(buffer_id, data, size), pool_(pool) { |
| 47 DCHECK(pool_); | 54 DCHECK(pool_); |
| 48 } | 55 } |
| 49 | 56 |
| 50 private: | 57 private: |
| 51 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); } | 58 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); } |
| 52 | 59 |
| 53 const scoped_refptr<VideoCaptureBufferPool> pool_; | 60 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 54 }; | 61 }; |
| 55 | 62 |
| 63 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { |
| 64 public: |
| 65 explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {} |
| 66 virtual ~SyncPointClientImpl() {} |
| 67 virtual uint32 InsertSyncPoint() OVERRIDE { |
| 68 return gl_helper_->InsertSyncPoint(); |
| 69 } |
| 70 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { |
| 71 gl_helper_->WaitSyncPoint(sync_point); |
| 72 } |
| 73 |
| 74 private: |
| 75 GLHelper* gl_helper_; |
| 76 }; |
| 77 |
| 78 void ReturnVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
| 79 uint32 sync_point) { |
| 80 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 81 #if defined(OS_ANDROID) |
| 82 GLHelper* gl_helper = |
| 83 ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
| 84 #else |
| 85 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
| 86 #endif |
| 87 DCHECK(gl_helper); |
| 88 gl_helper->WaitSyncPoint(sync_point); |
| 89 SyncPointClientImpl client(gl_helper); |
| 90 video_frame->UpdateReleaseSyncPoint(&client); |
| 91 } |
| 92 |
| 56 } // anonymous namespace | 93 } // anonymous namespace |
| 57 | 94 |
| 58 struct VideoCaptureController::ControllerClient { | 95 struct VideoCaptureController::ControllerClient { |
| 59 ControllerClient(const VideoCaptureControllerID& id, | 96 ControllerClient(const VideoCaptureControllerID& id, |
| 60 VideoCaptureControllerEventHandler* handler, | 97 VideoCaptureControllerEventHandler* handler, |
| 61 base::ProcessHandle render_process, | 98 base::ProcessHandle render_process, |
| 62 media::VideoCaptureSessionId session_id, | 99 media::VideoCaptureSessionId session_id, |
| 63 const media::VideoCaptureParams& params) | 100 const media::VideoCaptureParams& params) |
| 64 : controller_id(id), | 101 : controller_id(id), |
| 65 event_handler(handler), | 102 event_handler(handler), |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (client) { | 279 if (client) { |
| 243 client->session_closed = true; | 280 client->session_closed = true; |
| 244 client->event_handler->OnEnded(client->controller_id); | 281 client->event_handler->OnEnded(client->controller_id); |
| 245 } | 282 } |
| 246 } | 283 } |
| 247 | 284 |
| 248 void VideoCaptureController::ReturnBuffer( | 285 void VideoCaptureController::ReturnBuffer( |
| 249 const VideoCaptureControllerID& id, | 286 const VideoCaptureControllerID& id, |
| 250 VideoCaptureControllerEventHandler* event_handler, | 287 VideoCaptureControllerEventHandler* event_handler, |
| 251 int buffer_id, | 288 int buffer_id, |
| 252 const std::vector<uint32>& sync_points) { | 289 uint32 sync_point) { |
| 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 290 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 254 | 291 |
| 255 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 292 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 256 | 293 |
| 257 // If this buffer is not held by this client, or this client doesn't exist | 294 // If this buffer is not held by this client, or this client doesn't exist |
| 258 // in controller, do nothing. | 295 // in controller, do nothing. |
| 259 ControllerClient::ActiveBufferMap::iterator iter; | 296 ControllerClient::ActiveBufferMap::iterator iter; |
| 260 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 297 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
| 261 client->active_buffers.end()) { | 298 client->active_buffers.end()) { |
| 262 NOTREACHED(); | 299 NOTREACHED(); |
| 263 return; | 300 return; |
| 264 } | 301 } |
| 265 scoped_refptr<media::VideoFrame> frame = iter->second; | 302 scoped_refptr<media::VideoFrame> frame = iter->second; |
| 266 client->active_buffers.erase(iter); | 303 client->active_buffers.erase(iter); |
| 304 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 267 | 305 |
| 268 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { | 306 if (sync_point) |
| 269 for (size_t i = 0; i < sync_points.size(); i++) | 307 BrowserThread::PostTask(BrowserThread::UI, |
| 270 frame->AppendReleaseSyncPoint(sync_points[i]); | 308 FROM_HERE, |
| 271 } | 309 base::Bind(&ReturnVideoFrame, frame, sync_point)); |
| 272 | |
| 273 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | |
| 274 } | 310 } |
| 275 | 311 |
| 276 const media::VideoCaptureFormat& | 312 const media::VideoCaptureFormat& |
| 277 VideoCaptureController::GetVideoCaptureFormat() const { | 313 VideoCaptureController::GetVideoCaptureFormat() const { |
| 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 314 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 279 return video_capture_format_; | 315 return video_capture_format_; |
| 280 } | 316 } |
| 281 | 317 |
| 282 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> | 318 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> |
| 283 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( | 319 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } | 677 } |
| 642 return NULL; | 678 return NULL; |
| 643 } | 679 } |
| 644 | 680 |
| 645 int VideoCaptureController::GetClientCount() { | 681 int VideoCaptureController::GetClientCount() { |
| 646 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 682 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 647 return controller_clients_.size(); | 683 return controller_clients_.size(); |
| 648 } | 684 } |
| 649 | 685 |
| 650 } // namespace content | 686 } // namespace content |
| OLD | NEW |