| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_device_client.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "third_party/libyuv/include/libyuv.h" | 25 #include "third_party/libyuv/include/libyuv.h" |
| 26 | 26 |
| 27 using media::VideoCaptureFormat; | 27 using media::VideoCaptureFormat; |
| 28 using media::VideoFrame; | 28 using media::VideoFrame; |
| 29 using media::VideoFrameMetadata; | 29 using media::VideoFrameMetadata; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 // Class combining a Client::Buffer interface implementation and a pool buffer | 33 // Class combining a Client::Buffer interface implementation and a pool buffer |
| 34 // implementation to guarantee proper cleanup on destruction on our side. | 34 // implementation to guarantee proper cleanup on destruction on our side. |
| 35 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { | 35 class AutoReleaseBuffer : public device::VideoCaptureDevice::Client::Buffer { |
| 36 public: | 36 public: |
| 37 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, | 37 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, |
| 38 int buffer_id) | 38 int buffer_id) |
| 39 : id_(buffer_id), | 39 : id_(buffer_id), |
| 40 pool_(pool), | 40 pool_(pool), |
| 41 buffer_handle_(pool_->GetBufferHandle(buffer_id)) { | 41 buffer_handle_(pool_->GetBufferHandle(buffer_id)) { |
| 42 DCHECK(pool_.get()); | 42 DCHECK(pool_.get()); |
| 43 } | 43 } |
| 44 int id() const override { return id_; } | 44 int id() const override { return id_; } |
| 45 gfx::Size dimensions() const override { return buffer_handle_->dimensions(); } | 45 gfx::Size dimensions() const override { return buffer_handle_->dimensions(); } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 return; | 257 return; |
| 258 } | 258 } |
| 259 | 259 |
| 260 const VideoCaptureFormat output_format = VideoCaptureFormat( | 260 const VideoCaptureFormat output_format = VideoCaptureFormat( |
| 261 dimensions, frame_format.frame_rate, | 261 dimensions, frame_format.frame_rate, |
| 262 media::PIXEL_FORMAT_I420, output_pixel_storage); | 262 media::PIXEL_FORMAT_I420, output_pixel_storage); |
| 263 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, | 263 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, |
| 264 timestamp); | 264 timestamp); |
| 265 } | 265 } |
| 266 | 266 |
| 267 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 267 std::unique_ptr<device::VideoCaptureDevice::Client::Buffer> |
| 268 VideoCaptureDeviceClient::ReserveOutputBuffer( | 268 VideoCaptureDeviceClient::ReserveOutputBuffer( |
| 269 const gfx::Size& frame_size, | 269 const gfx::Size& frame_size, |
| 270 media::VideoPixelFormat pixel_format, | 270 media::VideoPixelFormat pixel_format, |
| 271 media::VideoPixelStorage pixel_storage) { | 271 media::VideoPixelStorage pixel_storage) { |
| 272 DCHECK_GT(frame_size.width(), 0); | 272 DCHECK_GT(frame_size.width(), 0); |
| 273 DCHECK_GT(frame_size.height(), 0); | 273 DCHECK_GT(frame_size.height(), 0); |
| 274 // Currently, only I420 pixel format is supported. | 274 // Currently, only I420 pixel format is supported. |
| 275 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | 275 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); |
| 276 | 276 |
| 277 // TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if | 277 // TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame( | 335 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame( |
| 336 std::unique_ptr<Buffer> buffer, | 336 std::unique_ptr<Buffer> buffer, |
| 337 const scoped_refptr<VideoFrame>& frame) { | 337 const scoped_refptr<VideoFrame>& frame) { |
| 338 BrowserThread::PostTask( | 338 BrowserThread::PostTask( |
| 339 BrowserThread::IO, FROM_HERE, | 339 BrowserThread::IO, FROM_HERE, |
| 340 base::Bind( | 340 base::Bind( |
| 341 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, | 341 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, |
| 342 controller_, base::Passed(&buffer), frame)); | 342 controller_, base::Passed(&buffer), frame)); |
| 343 } | 343 } |
| 344 | 344 |
| 345 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 345 std::unique_ptr<device::VideoCaptureDevice::Client::Buffer> |
| 346 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( | 346 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( |
| 347 const gfx::Size& dimensions, | 347 const gfx::Size& dimensions, |
| 348 media::VideoPixelFormat format, | 348 media::VideoPixelFormat format, |
| 349 media::VideoPixelStorage storage) { | 349 media::VideoPixelStorage storage) { |
| 350 const int buffer_id = | 350 const int buffer_id = |
| 351 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); | 351 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); |
| 352 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 352 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 353 return nullptr; | 353 return nullptr; |
| 354 return base::WrapUnique<Buffer>( | 354 return base::WrapUnique<Buffer>( |
| 355 new AutoReleaseBuffer(buffer_pool_, buffer_id)); | 355 new AutoReleaseBuffer(buffer_pool_, buffer_id)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 375 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 375 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 376 base::Bind(&VideoCaptureController::DoLogOnIOThread, | 376 base::Bind(&VideoCaptureController::DoLogOnIOThread, |
| 377 controller_, message)); | 377 controller_, message)); |
| 378 } | 378 } |
| 379 | 379 |
| 380 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { | 380 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { |
| 381 // VideoCaptureBufferPool::GetBufferPoolUtilization() is thread-safe. | 381 // VideoCaptureBufferPool::GetBufferPoolUtilization() is thread-safe. |
| 382 return buffer_pool_->GetBufferPoolUtilization(); | 382 return buffer_pool_->GetBufferPoolUtilization(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 385 std::unique_ptr<device::VideoCaptureDevice::Client::Buffer> |
| 386 VideoCaptureDeviceClient::ReserveI420OutputBuffer( | 386 VideoCaptureDeviceClient::ReserveI420OutputBuffer( |
| 387 const gfx::Size& dimensions, | 387 const gfx::Size& dimensions, |
| 388 media::VideoPixelStorage storage, | 388 media::VideoPixelStorage storage, |
| 389 uint8_t** y_plane_data, | 389 uint8_t** y_plane_data, |
| 390 uint8_t** u_plane_data, | 390 uint8_t** u_plane_data, |
| 391 uint8_t** v_plane_data) { | 391 uint8_t** v_plane_data) { |
| 392 DCHECK(storage == media::PIXEL_STORAGE_GPUMEMORYBUFFER || | 392 DCHECK(storage == media::PIXEL_STORAGE_GPUMEMORYBUFFER || |
| 393 storage == media::PIXEL_STORAGE_CPU); | 393 storage == media::PIXEL_STORAGE_CPU); |
| 394 DCHECK(dimensions.height()); | 394 DCHECK(dimensions.height()); |
| 395 DCHECK(dimensions.width()); | 395 DCHECK(dimensions.width()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 421 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); | 421 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); |
| 422 *v_plane_data = | 422 *v_plane_data = |
| 423 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); | 423 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); |
| 424 return buffer; | 424 return buffer; |
| 425 } | 425 } |
| 426 NOTREACHED(); | 426 NOTREACHED(); |
| 427 return std::unique_ptr<Buffer>(); | 427 return std::unique_ptr<Buffer>(); |
| 428 } | 428 } |
| 429 | 429 |
| 430 } // namespace content | 430 } // namespace content |
| OLD | NEW |