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 "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/debug/debugger.h" | 8 #include "base/debug/debugger.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 CHECK_EQ(format, media::VideoFrame::I420); | 329 CHECK_EQ(format, media::VideoFrame::I420); |
330 const size_t frame_bytes = | 330 const size_t frame_bytes = |
331 media::VideoFrame::AllocationSize(media::VideoFrame::I420, dimensions); | 331 media::VideoFrame::AllocationSize(media::VideoFrame::I420, dimensions); |
332 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. | 332 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. |
333 int buffer_id = | 333 int buffer_id = |
334 buffer_pool_->ReserveForProducer(frame_bytes, &buffer_id_to_drop); | 334 buffer_pool_->ReserveForProducer(frame_bytes, &buffer_id_to_drop); |
335 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 335 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
336 return NULL; | 336 return NULL; |
337 void* data; | 337 void* data; |
338 size_t size; | 338 size_t size; |
339 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); | 339 base::SharedMemoryHandle handle; |
| 340 buffer_pool_->GetBufferInfo(buffer_id, &data, &size, &handle); |
340 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( | 341 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( |
341 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size)); | 342 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size, handle)); |
342 } | 343 } |
343 | 344 |
344 void OnIncomingCapturedVideoFrame( | 345 void OnIncomingCapturedVideoFrame( |
345 const scoped_refptr<Buffer>& buffer, | 346 const scoped_refptr<Buffer>& buffer, |
346 const scoped_refptr<media::VideoFrame>& frame, | 347 const scoped_refptr<media::VideoFrame>& frame, |
347 const base::TimeTicks& timestamp) override { | 348 const base::TimeTicks& timestamp) override { |
348 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->visible_rect().size()); | 349 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->visible_rect().size()); |
349 EXPECT_EQ(media::VideoFrame::I420, frame->format()); | 350 EXPECT_EQ(media::VideoFrame::I420, frame->format()); |
350 double frame_rate = 0; | 351 double frame_rate = 0; |
351 EXPECT_TRUE( | 352 EXPECT_TRUE( |
(...skipping 10 matching lines...) Expand all Loading... |
362 } | 363 } |
363 | 364 |
364 void OnError(const std::string& reason) override { error_callback_.Run(); } | 365 void OnError(const std::string& reason) override { error_callback_.Run(); } |
365 | 366 |
366 private: | 367 private: |
367 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { | 368 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { |
368 public: | 369 public: |
369 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, | 370 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, |
370 int buffer_id, | 371 int buffer_id, |
371 void* data, | 372 void* data, |
372 size_t size) | 373 size_t size, |
| 374 base::SharedMemoryHandle handle) |
373 : pool_(pool), | 375 : pool_(pool), |
374 id_(buffer_id), | 376 id_(buffer_id), |
375 data_(data), | 377 data_(data), |
376 size_(size) { | 378 size_(size), |
| 379 handle_(handle) { |
377 DCHECK(pool_.get()); | 380 DCHECK(pool_.get()); |
378 } | 381 } |
379 int id() const override { return id_; } | 382 int id() const override { return id_; } |
380 void* data() const override { return data_; } | 383 void* data() const override { return data_; } |
381 size_t size() const override { return size_; } | 384 size_t size() const override { return size_; } |
| 385 base::SharedMemoryHandle handle() const override { return handle_; } |
382 | 386 |
383 private: | 387 private: |
384 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } | 388 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } |
385 | 389 |
386 const scoped_refptr<VideoCaptureBufferPool> pool_; | 390 const scoped_refptr<VideoCaptureBufferPool> pool_; |
387 const int id_; | 391 const int id_; |
388 void* const data_; | 392 void* const data_; |
389 const size_t size_; | 393 const size_t size_; |
| 394 const base::SharedMemoryHandle handle_; |
390 }; | 395 }; |
391 | 396 |
392 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 397 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
393 base::Callback<void(SkColor)> color_callback_; | 398 base::Callback<void(SkColor)> color_callback_; |
394 base::Closure error_callback_; | 399 base::Closure error_callback_; |
395 | 400 |
396 DISALLOW_COPY_AND_ASSIGN(StubClient); | 401 DISALLOW_COPY_AND_ASSIGN(StubClient); |
397 }; | 402 }; |
398 | 403 |
399 class StubClientObserver { | 404 class StubClientObserver { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 source()->SetSolidColor(SK_ColorGREEN); | 862 source()->SetSolidColor(SK_ColorGREEN); |
858 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 863 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
859 source()->SetSolidColor(SK_ColorRED); | 864 source()->SetSolidColor(SK_ColorRED); |
860 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 865 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
861 | 866 |
862 device()->StopAndDeAllocate(); | 867 device()->StopAndDeAllocate(); |
863 } | 868 } |
864 | 869 |
865 } // namespace | 870 } // namespace |
866 } // namespace content | 871 } // namespace content |
OLD | NEW |