| 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 "media/capture/video/video_capture_device_client.h" | 5 #include "media/capture/video/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 23 matching lines...) Expand all Loading... |
| 34 pixel_format == media::PIXEL_FORMAT_Y16); | 34 pixel_format == media::PIXEL_FORMAT_Y16); |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 namespace media { | 38 namespace media { |
| 39 | 39 |
| 40 // Class combining a Client::Buffer interface implementation and a pool buffer | 40 // Class combining a Client::Buffer interface implementation and a pool buffer |
| 41 // implementation to guarantee proper cleanup on destruction on our side. | 41 // implementation to guarantee proper cleanup on destruction on our side. |
| 42 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { | 42 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { |
| 43 public: | 43 public: |
| 44 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, | 44 AutoReleaseBuffer(scoped_refptr<VideoCaptureBufferPool> pool, int buffer_id) |
| 45 int buffer_id) | |
| 46 : id_(buffer_id), | 45 : id_(buffer_id), |
| 47 pool_(pool), | 46 pool_(std::move(pool)), |
| 48 buffer_handle_(pool_->GetBufferHandle(buffer_id)) { | 47 buffer_handle_(pool_->GetBufferHandle(buffer_id)) { |
| 49 DCHECK(pool_.get()); | 48 DCHECK(pool_.get()); |
| 50 } | 49 } |
| 51 int id() const override { return id_; } | 50 int id() const override { return id_; } |
| 52 gfx::Size dimensions() const override { return buffer_handle_->dimensions(); } | 51 gfx::Size dimensions() const override { return buffer_handle_->dimensions(); } |
| 53 size_t mapped_size() const override { return buffer_handle_->mapped_size(); } | 52 size_t mapped_size() const override { return buffer_handle_->mapped_size(); } |
| 54 void* data(int plane) override { return buffer_handle_->data(plane); } | 53 void* data(int plane) override { return buffer_handle_->data(plane); } |
| 55 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 54 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 56 base::FileDescriptor AsPlatformFile() override { | 55 base::FileDescriptor AsPlatformFile() override { |
| 57 return buffer_handle_->AsPlatformFile(); | 56 return buffer_handle_->AsPlatformFile(); |
| 58 } | 57 } |
| 59 #endif | 58 #endif |
| 60 bool IsBackedByVideoFrame() const override { | 59 bool IsBackedByVideoFrame() const override { |
| 61 return buffer_handle_->IsBackedByVideoFrame(); | 60 return buffer_handle_->IsBackedByVideoFrame(); |
| 62 } | 61 } |
| 63 scoped_refptr<VideoFrame> GetVideoFrame() override { | 62 scoped_refptr<VideoFrame> GetVideoFrame() override { |
| 64 return buffer_handle_->GetVideoFrame(); | 63 return buffer_handle_->GetVideoFrame(); |
| 65 } | 64 } |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } | 67 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } |
| 69 | 68 |
| 70 const int id_; | 69 const int id_; |
| 71 const scoped_refptr<VideoCaptureBufferPool> pool_; | 70 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 72 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; | 71 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; |
| 73 }; | 72 }; |
| 74 | 73 |
| 75 VideoCaptureDeviceClient::VideoCaptureDeviceClient( | 74 VideoCaptureDeviceClient::VideoCaptureDeviceClient( |
| 76 std::unique_ptr<VideoFrameReceiver> receiver, | 75 std::unique_ptr<VideoFrameReceiver> receiver, |
| 77 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, | 76 scoped_refptr<VideoCaptureBufferPool> buffer_pool, |
| 78 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory) | 77 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory) |
| 79 : receiver_(std::move(receiver)), | 78 : receiver_(std::move(receiver)), |
| 80 jpeg_decoder_factory_callback_(jpeg_decoder_factory), | 79 jpeg_decoder_factory_callback_(jpeg_decoder_factory), |
| 81 external_jpeg_decoder_initialized_(false), | 80 external_jpeg_decoder_initialized_(false), |
| 82 buffer_pool_(buffer_pool), | 81 buffer_pool_(std::move(buffer_pool)), |
| 83 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} | 82 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} |
| 84 | 83 |
| 85 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { | 84 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { |
| 86 // This should be on the platform auxiliary thread since | 85 // This should be on the platform auxiliary thread since |
| 87 // |external_jpeg_decoder_| need to be destructed on the same thread as | 86 // |external_jpeg_decoder_| need to be destructed on the same thread as |
| 88 // OnIncomingCapturedData. | 87 // OnIncomingCapturedData. |
| 89 } | 88 } |
| 90 | 89 |
| 91 void VideoCaptureDeviceClient::OnIncomingCapturedData( | 90 void VideoCaptureDeviceClient::OnIncomingCapturedData( |
| 92 const uint8_t* data, | 91 const uint8_t* data, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 VideoFrame::AllocationSize(frame_format.pixel_format, | 304 VideoFrame::AllocationSize(frame_format.pixel_format, |
| 306 frame_format.frame_size), | 305 frame_format.frame_size), |
| 307 base::SharedMemory::NULLHandle(), 0u, timestamp); | 306 base::SharedMemory::NULLHandle(), 0u, timestamp); |
| 308 } | 307 } |
| 309 if (!frame) | 308 if (!frame) |
| 310 return; | 309 return; |
| 311 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 310 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 312 frame_format.frame_rate); | 311 frame_format.frame_rate); |
| 313 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, | 312 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, |
| 314 reference_time); | 313 reference_time); |
| 315 OnIncomingCapturedVideoFrame(std::move(buffer), frame); | 314 OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); |
| 316 } | 315 } |
| 317 | 316 |
| 318 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame( | 317 void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame( |
| 319 std::unique_ptr<Buffer> buffer, | 318 std::unique_ptr<Buffer> buffer, |
| 320 const scoped_refptr<VideoFrame>& frame) { | 319 scoped_refptr<VideoFrame> frame) { |
| 321 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), frame); | 320 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); |
| 322 } | 321 } |
| 323 | 322 |
| 324 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 323 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> |
| 325 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( | 324 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( |
| 326 const gfx::Size& dimensions, | 325 const gfx::Size& dimensions, |
| 327 media::VideoPixelFormat format, | 326 media::VideoPixelFormat format, |
| 328 media::VideoPixelStorage storage) { | 327 media::VideoPixelStorage storage) { |
| 329 const int buffer_id = | 328 const int buffer_id = |
| 330 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); | 329 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); |
| 331 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 330 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 return; | 404 return; |
| 406 memcpy(buffer->data(), data, length); | 405 memcpy(buffer->data(), data, length); |
| 407 const VideoCaptureFormat output_format = | 406 const VideoCaptureFormat output_format = |
| 408 VideoCaptureFormat(frame_format.frame_size, frame_format.frame_rate, | 407 VideoCaptureFormat(frame_format.frame_size, frame_format.frame_rate, |
| 409 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); | 408 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); |
| 410 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, | 409 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, |
| 411 timestamp); | 410 timestamp); |
| 412 } | 411 } |
| 413 | 412 |
| 414 } // namespace media | 413 } // namespace media |
| OLD | NEW |