Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
wuchengli
2015/04/21 06:05:36
Please provide performance data of HW and SW JPEG
kcwu
2015/05/08 14:42:41
Done.
| |
| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 media::VideoPixelFormat format, | 339 media::VideoPixelFormat format, |
| 340 const gfx::Size& dimensions) override { | 340 const gfx::Size& dimensions) override { |
| 341 CHECK_EQ(format, media::PIXEL_FORMAT_I420); | 341 CHECK_EQ(format, media::PIXEL_FORMAT_I420); |
| 342 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. | 342 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. |
| 343 int buffer_id = buffer_pool_->ReserveForProducer(format, dimensions, | 343 int buffer_id = buffer_pool_->ReserveForProducer(format, dimensions, |
| 344 &buffer_id_to_drop); | 344 &buffer_id_to_drop); |
| 345 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 345 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 346 return NULL; | 346 return NULL; |
| 347 void* data; | 347 void* data; |
| 348 size_t size; | 348 size_t size; |
| 349 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); | 349 base::SharedMemoryHandle handle; |
| 350 buffer_pool_->GetBufferInfo(buffer_id, &data, &size, &handle); | |
| 350 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( | 351 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( |
| 351 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size)); | 352 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size, handle)); |
| 352 } | 353 } |
| 353 | 354 |
| 354 void OnIncomingCapturedVideoFrame( | 355 void OnIncomingCapturedVideoFrame( |
| 355 const scoped_refptr<Buffer>& buffer, | 356 const scoped_refptr<Buffer>& buffer, |
| 356 const scoped_refptr<media::VideoFrame>& frame, | 357 const scoped_refptr<media::VideoFrame>& frame, |
| 357 const base::TimeTicks& timestamp) override { | 358 const base::TimeTicks& timestamp) override { |
| 358 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->visible_rect().size()); | 359 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->visible_rect().size()); |
| 359 EXPECT_EQ(media::VideoFrame::I420, frame->format()); | 360 EXPECT_EQ(media::VideoFrame::I420, frame->format()); |
| 360 double frame_rate = 0; | 361 double frame_rate = 0; |
| 361 EXPECT_TRUE( | 362 EXPECT_TRUE( |
| 362 frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 363 frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 363 &frame_rate)); | 364 &frame_rate)); |
| 364 EXPECT_EQ(kTestFramesPerSecond, frame_rate); | 365 EXPECT_EQ(kTestFramesPerSecond, frame_rate); |
| 365 uint8 yuv[3]; | 366 uint8 yuv[3]; |
| 366 for (int plane = 0; plane < 3; ++plane) | 367 for (int plane = 0; plane < 3; ++plane) |
| 367 yuv[plane] = frame->visible_data(plane)[0]; | 368 yuv[plane] = frame->visible_data(plane)[0]; |
| 368 // TODO(nick): We just look at the first pixel presently, because if | 369 // TODO(nick): We just look at the first pixel presently, because if |
| 369 // the analysis is too slow, the backlog of frames will grow without bound | 370 // the analysis is too slow, the backlog of frames will grow without bound |
| 370 // and trouble erupts. http://crbug.com/174519 | 371 // and trouble erupts. http://crbug.com/174519 |
| 371 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); | 372 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); |
| 372 } | 373 } |
| 373 | 374 |
| 374 void OnError(const std::string& reason) override { error_callback_.Run(); } | 375 void OnError(const std::string& reason) override { error_callback_.Run(); } |
| 375 | 376 |
| 376 private: | 377 private: |
| 377 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { | 378 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { |
| 378 public: | 379 public: |
| 379 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, | 380 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, |
| 380 int buffer_id, | 381 int buffer_id, |
| 381 void* data, | 382 void* data, |
| 382 size_t size) | 383 size_t size, |
| 384 base::SharedMemoryHandle handle) | |
| 383 : pool_(pool), | 385 : pool_(pool), |
| 384 id_(buffer_id), | 386 id_(buffer_id), |
| 385 data_(data), | 387 data_(data), |
| 386 size_(size) { | 388 size_(size), |
| 389 handle_(handle) { | |
| 387 DCHECK(pool_.get()); | 390 DCHECK(pool_.get()); |
| 388 } | 391 } |
| 389 int id() const override { return id_; } | 392 int id() const override { return id_; } |
| 390 void* data() const override { return data_; } | 393 void* data() const override { return data_; } |
| 391 size_t size() const override { return size_; } | 394 size_t size() const override { return size_; } |
| 395 base::SharedMemoryHandle handle() const override { return handle_; } | |
| 392 | 396 |
| 393 private: | 397 private: |
| 394 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } | 398 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } |
| 395 | 399 |
| 396 const scoped_refptr<VideoCaptureBufferPool> pool_; | 400 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 397 const int id_; | 401 const int id_; |
| 398 void* const data_; | 402 void* const data_; |
| 399 const size_t size_; | 403 const size_t size_; |
| 404 const base::SharedMemoryHandle handle_; | |
| 400 }; | 405 }; |
| 401 | 406 |
| 402 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 407 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 403 base::Callback<void(SkColor)> color_callback_; | 408 base::Callback<void(SkColor)> color_callback_; |
| 404 base::Closure error_callback_; | 409 base::Closure error_callback_; |
| 405 | 410 |
| 406 DISALLOW_COPY_AND_ASSIGN(StubClient); | 411 DISALLOW_COPY_AND_ASSIGN(StubClient); |
| 407 }; | 412 }; |
| 408 | 413 |
| 409 class StubClientObserver { | 414 class StubClientObserver { |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 source()->SetSolidColor(SK_ColorGREEN); | 872 source()->SetSolidColor(SK_ColorGREEN); |
| 868 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 873 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
| 869 source()->SetSolidColor(SK_ColorRED); | 874 source()->SetSolidColor(SK_ColorRED); |
| 870 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 875 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
| 871 | 876 |
| 872 device()->StopAndDeAllocate(); | 877 device()->StopAndDeAllocate(); |
| 873 } | 878 } |
| 874 | 879 |
| 875 } // namespace | 880 } // namespace |
| 876 } // namespace content | 881 } // namespace content |
| OLD | NEW |