| 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/media/capture/web_contents_video_capture_device.h" | 5 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 368 |
| 369 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 369 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
| 370 | 370 |
| 371 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> ReserveOutputBuffer( | 371 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> ReserveOutputBuffer( |
| 372 const gfx::Size& dimensions, | 372 const gfx::Size& dimensions, |
| 373 media::VideoPixelFormat format, | 373 media::VideoPixelFormat format, |
| 374 media::VideoPixelStorage storage) override { | 374 media::VideoPixelStorage storage) override { |
| 375 CHECK_EQ(format, media::PIXEL_FORMAT_I420); | 375 CHECK_EQ(format, media::PIXEL_FORMAT_I420); |
| 376 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. | 376 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. |
| 377 const int buffer_id = buffer_pool_->ReserveForProducer( | 377 const int buffer_id = buffer_pool_->ReserveForProducer( |
| 378 format, storage, dimensions, &buffer_id_to_drop); | 378 dimensions, format, storage, &buffer_id_to_drop); |
| 379 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 379 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 380 return NULL; | 380 return NULL; |
| 381 | 381 |
| 382 return scoped_ptr<media::VideoCaptureDevice::Client::Buffer>( | 382 return scoped_ptr<media::VideoCaptureDevice::Client::Buffer>( |
| 383 new AutoReleaseBuffer( | 383 new AutoReleaseBuffer( |
| 384 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id)); | 384 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id)); |
| 385 } | 385 } |
| 386 |
| 386 // Trampoline method to workaround GMOCK problems with scoped_ptr<>. | 387 // Trampoline method to workaround GMOCK problems with scoped_ptr<>. |
| 387 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer, | 388 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer, |
| 388 const media::VideoCaptureFormat& frame_format, | 389 const media::VideoCaptureFormat& frame_format, |
| 389 const base::TimeTicks& timestamp) override { | 390 const base::TimeTicks& timestamp) override { |
| 390 DoOnIncomingCapturedBuffer(); | 391 DoOnIncomingCapturedBuffer(); |
| 391 } | 392 } |
| 392 | 393 |
| 393 void OnIncomingCapturedVideoFrame( | 394 void OnIncomingCapturedVideoFrame( |
| 394 scoped_ptr<Buffer> buffer, | 395 scoped_ptr<Buffer> buffer, |
| 395 const scoped_refptr<media::VideoFrame>& frame, | 396 const scoped_refptr<media::VideoFrame>& frame, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 412 const int center_offset_uv = | 413 const int center_offset_uv = |
| 413 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + | 414 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + |
| 414 (center.x() / 2); | 415 (center.x() / 2); |
| 415 report_callback_.Run( | 416 report_callback_.Run( |
| 416 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], | 417 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], |
| 417 frame->data(VideoFrame::kUPlane)[center_offset_uv], | 418 frame->data(VideoFrame::kUPlane)[center_offset_uv], |
| 418 frame->data(VideoFrame::kVPlane)[center_offset_uv]), | 419 frame->data(VideoFrame::kVPlane)[center_offset_uv]), |
| 419 frame->visible_rect().size()); | 420 frame->visible_rect().size()); |
| 420 } | 421 } |
| 421 | 422 |
| 423 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> |
| 424 ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
| 425 media::VideoPixelFormat format, |
| 426 media::VideoPixelStorage storage) override { |
| 427 CHECK_EQ(format, media::PIXEL_FORMAT_I420); |
| 428 const int buffer_id = |
| 429 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); |
| 430 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 431 return nullptr; |
| 432 return scoped_ptr<media::VideoCaptureDevice::Client::Buffer>( |
| 433 new AutoReleaseBuffer( |
| 434 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id)); |
| 435 } |
| 436 |
| 422 void OnError(const tracked_objects::Location& from_here, | 437 void OnError(const tracked_objects::Location& from_here, |
| 423 const std::string& reason) override { | 438 const std::string& reason) override { |
| 424 error_callback_.Run(); | 439 error_callback_.Run(); |
| 425 } | 440 } |
| 426 | 441 |
| 427 double GetBufferPoolUtilization() const override { return 0.0; } | 442 double GetBufferPoolUtilization() const override { return 0.0; } |
| 428 | 443 |
| 429 private: | 444 private: |
| 430 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { | 445 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { |
| 431 public: | 446 public: |
| 432 AutoReleaseBuffer( | 447 AutoReleaseBuffer( |
| 433 const scoped_refptr<VideoCaptureBufferPool>& pool, | 448 const scoped_refptr<VideoCaptureBufferPool>& pool, |
| 434 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle, | 449 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle, |
| 435 int buffer_id) | 450 int buffer_id) |
| 436 : id_(buffer_id), | 451 : id_(buffer_id), |
| 437 pool_(pool), | 452 pool_(pool), |
| 438 buffer_handle_(std::move(buffer_handle)) { | 453 buffer_handle_(std::move(buffer_handle)) { |
| 439 DCHECK(pool_); | 454 DCHECK(pool_); |
| 440 } | 455 } |
| 441 int id() const override { return id_; } | 456 int id() const override { return id_; } |
| 442 gfx::Size dimensions() const override { return gfx::Size(); } | 457 gfx::Size dimensions() const override { |
| 458 return buffer_handle_->dimensions(); |
| 459 } |
| 443 size_t mapped_size() const override { | 460 size_t mapped_size() const override { |
| 444 return buffer_handle_->mapped_size(); | 461 return buffer_handle_->mapped_size(); |
| 445 } | 462 } |
| 446 void* data(int plane) override { return buffer_handle_->data(plane); } | 463 void* data(int plane) override { return buffer_handle_->data(plane); } |
| 447 ClientBuffer AsClientBuffer(int plane) override { return nullptr; } | 464 ClientBuffer AsClientBuffer(int plane) override { return nullptr; } |
| 448 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 465 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 449 base::FileDescriptor AsPlatformFile() override { | 466 base::FileDescriptor AsPlatformFile() override { |
| 450 return base::FileDescriptor(); | 467 return base::FileDescriptor(); |
| 451 } | 468 } |
| 452 #endif | 469 #endif |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); | 1166 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); |
| 1150 RunTestForPreferredSize( | 1167 RunTestForPreferredSize( |
| 1151 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); | 1168 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); |
| 1152 RunTestForPreferredSize( | 1169 RunTestForPreferredSize( |
| 1153 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); | 1170 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); |
| 1154 } | 1171 } |
| 1155 } | 1172 } |
| 1156 | 1173 |
| 1157 } // namespace | 1174 } // namespace |
| 1158 } // namespace content | 1175 } // namespace content |
| OLD | NEW |