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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); |
340 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( | 340 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( |
341 new PoolBuffer(buffer_pool_, buffer_id, data, size)); | 341 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size)); |
342 } | 342 } |
343 | 343 |
344 void OnIncomingCapturedVideoFrame( | 344 void OnIncomingCapturedVideoFrame( |
345 const scoped_refptr<Buffer>& buffer, | 345 const scoped_refptr<Buffer>& buffer, |
346 const media::VideoCaptureFormat& buffer_format, | 346 const media::VideoCaptureFormat& buffer_format, |
347 const scoped_refptr<media::VideoFrame>& frame, | 347 const scoped_refptr<media::VideoFrame>& frame, |
348 const base::TimeTicks& timestamp) override { | 348 const base::TimeTicks& timestamp) override { |
349 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), buffer_format.frame_size); | 349 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), buffer_format.frame_size); |
350 EXPECT_EQ(media::PIXEL_FORMAT_I420, buffer_format.pixel_format); | 350 EXPECT_EQ(media::PIXEL_FORMAT_I420, buffer_format.pixel_format); |
351 EXPECT_EQ(media::VideoFrame::I420, frame->format()); | 351 EXPECT_EQ(media::VideoFrame::I420, frame->format()); |
352 uint8 yuv[3]; | 352 uint8 yuv[3]; |
353 for (int plane = 0; plane < 3; ++plane) | 353 for (int plane = 0; plane < 3; ++plane) |
354 yuv[plane] = frame->data(plane)[0]; | 354 yuv[plane] = frame->data(plane)[0]; |
355 // TODO(nick): We just look at the first pixel presently, because if | 355 // TODO(nick): We just look at the first pixel presently, because if |
356 // the analysis is too slow, the backlog of frames will grow without bound | 356 // the analysis is too slow, the backlog of frames will grow without bound |
357 // and trouble erupts. http://crbug.com/174519 | 357 // and trouble erupts. http://crbug.com/174519 |
358 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); | 358 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); |
359 } | 359 } |
360 | 360 |
361 void OnError(const std::string& reason) override { error_callback_.Run(); } | 361 void OnError(const std::string& reason) override { error_callback_.Run(); } |
362 | 362 |
363 private: | 363 private: |
364 class PoolBuffer : public media::VideoCaptureDevice::Client::Buffer { | 364 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { |
365 public: | 365 public: |
366 PoolBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, | 366 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, |
367 int buffer_id, | 367 int buffer_id, |
368 void* data, | 368 void* data, |
369 size_t size) | 369 size_t size) |
370 : Buffer(buffer_id, data, size), pool_(pool) {} | 370 : pool_(pool), |
| 371 id_(buffer_id), |
| 372 data_(data), |
| 373 size_(size) { |
| 374 DCHECK(pool_.get()); |
| 375 } |
| 376 int id() const override { return id_; } |
| 377 void* data() const override { return data_; } |
| 378 size_t size() const override { return size_; } |
371 | 379 |
372 private: | 380 private: |
373 ~PoolBuffer() override { pool_->RelinquishProducerReservation(id()); } | 381 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } |
| 382 |
374 const scoped_refptr<VideoCaptureBufferPool> pool_; | 383 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 384 const int id_; |
| 385 void* const data_; |
| 386 const size_t size_; |
375 }; | 387 }; |
376 | 388 |
377 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 389 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
378 base::Callback<void(SkColor)> color_callback_; | 390 base::Callback<void(SkColor)> color_callback_; |
379 base::Closure error_callback_; | 391 base::Closure error_callback_; |
380 | 392 |
381 DISALLOW_COPY_AND_ASSIGN(StubClient); | 393 DISALLOW_COPY_AND_ASSIGN(StubClient); |
382 }; | 394 }; |
383 | 395 |
384 class StubClientObserver { | 396 class StubClientObserver { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 source()->SetSolidColor(SK_ColorGREEN); | 854 source()->SetSolidColor(SK_ColorGREEN); |
843 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 855 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
844 source()->SetSolidColor(SK_ColorRED); | 856 source()->SetSolidColor(SK_ColorRED); |
845 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 857 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
846 | 858 |
847 device()->StopAndDeAllocate(); | 859 device()->StopAndDeAllocate(); |
848 } | 860 } |
849 | 861 |
850 } // namespace | 862 } // namespace |
851 } // namespace content | 863 } // namespace content |
OLD | NEW |