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/renderer_host/media/web_contents_video_capture_device.
h" | 5 #include "content/browser/renderer_host/media/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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 class StubClient : public media::VideoCaptureDevice::Client { | 308 class StubClient : public media::VideoCaptureDevice::Client { |
309 public: | 309 public: |
310 StubClient(const base::Callback<void(SkColor)>& color_callback, | 310 StubClient(const base::Callback<void(SkColor)>& color_callback, |
311 const base::Closure& error_callback) | 311 const base::Closure& error_callback) |
312 : color_callback_(color_callback), | 312 : color_callback_(color_callback), |
313 error_callback_(error_callback) { | 313 error_callback_(error_callback) { |
314 buffer_pool_ = new VideoCaptureBufferPool(2); | 314 buffer_pool_ = new VideoCaptureBufferPool(2); |
315 } | 315 } |
316 virtual ~StubClient() {} | 316 virtual ~StubClient() {} |
317 | 317 |
318 virtual scoped_refptr<media::VideoFrame> ReserveOutputBuffer( | 318 virtual scoped_refptr<media::VideoCaptureDevice::Client::Buffer> |
319 const gfx::Size& size) OVERRIDE { | 319 ReserveOutputBuffer(media::VideoFrame::Format format, |
| 320 const gfx::Size& dimensions) OVERRIDE { |
| 321 const size_t frame_bytes = |
| 322 media::VideoFrame::AllocationSize(format, dimensions); |
320 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. | 323 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. |
321 return buffer_pool_->ReserveI420VideoFrame(size, 0, &buffer_id_to_drop); | 324 int buffer_id = |
| 325 buffer_pool_->ReserveForProducer(frame_bytes, &buffer_id_to_drop); |
| 326 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 327 return NULL; |
| 328 void* data; |
| 329 size_t size; |
| 330 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); |
| 331 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( |
| 332 new PoolBuffer(buffer_pool_, buffer_id, data, size)); |
322 } | 333 } |
323 | 334 |
324 virtual void OnIncomingCapturedFrame( | 335 virtual void OnIncomingCapturedFrame( |
325 const uint8* data, | 336 const uint8* data, |
326 int length, | 337 int length, |
327 base::Time timestamp, | 338 base::Time timestamp, |
328 int rotation, | 339 int rotation, |
329 bool flip_vert, | 340 bool flip_vert, |
330 bool flip_horiz, | 341 bool flip_horiz, |
331 const media::VideoCaptureCapability& frame_info) OVERRIDE { | 342 const media::VideoCaptureCapability& frame_info) OVERRIDE { |
332 FAIL(); | 343 FAIL(); |
333 } | 344 } |
334 | 345 |
335 virtual void OnIncomingCapturedVideoFrame( | 346 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, |
336 const scoped_refptr<media::VideoFrame>& frame, | 347 media::VideoFrame::Format format, |
337 base::Time timestamp, | 348 const gfx::Size& dimensions, |
338 int frame_rate) OVERRIDE { | 349 base::Time timestamp, |
339 EXPECT_EQ(kTestFramesPerSecond, frame_rate); | 350 int frame_rate) OVERRIDE { |
340 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->coded_size()); | 351 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), dimensions); |
341 EXPECT_EQ(media::VideoFrame::I420, frame->format()); | 352 EXPECT_EQ(media::VideoFrame::I420, format); |
342 EXPECT_LE( | |
343 0, | |
344 buffer_pool_->RecognizeReservedBuffer(frame->shared_memory_handle())); | |
345 uint8 yuv[3]; | 353 uint8 yuv[3]; |
| 354 size_t offset = 0; |
346 for (int plane = 0; plane < 3; ++plane) { | 355 for (int plane = 0; plane < 3; ++plane) { |
347 yuv[plane] = frame->data(plane)[0]; | 356 yuv[plane] = reinterpret_cast<uint8*>(buffer->data())[offset]; |
| 357 offset += media::VideoFrame::PlaneAllocationSize( |
| 358 media::VideoFrame::I420, plane, dimensions); |
348 } | 359 } |
349 // TODO(nick): We just look at the first pixel presently, because if | 360 // TODO(nick): We just look at the first pixel presently, because if |
350 // the analysis is too slow, the backlog of frames will grow without bound | 361 // the analysis is too slow, the backlog of frames will grow without bound |
351 // and trouble erupts. http://crbug.com/174519 | 362 // and trouble erupts. http://crbug.com/174519 |
352 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); | 363 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); |
353 } | 364 } |
354 | 365 |
355 virtual void OnError() OVERRIDE { | 366 virtual void OnError() OVERRIDE { |
356 error_callback_.Run(); | 367 error_callback_.Run(); |
357 } | 368 } |
358 | 369 |
359 private: | 370 private: |
| 371 class PoolBuffer : public media::VideoCaptureDevice::Client::Buffer { |
| 372 public: |
| 373 PoolBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, |
| 374 int buffer_id, |
| 375 void* data, |
| 376 size_t size) |
| 377 : Buffer(buffer_id, data, size), pool_(pool) {} |
| 378 |
| 379 private: |
| 380 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); } |
| 381 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 382 }; |
| 383 |
360 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 384 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
361 base::Callback<void(SkColor)> color_callback_; | 385 base::Callback<void(SkColor)> color_callback_; |
362 base::Closure error_callback_; | 386 base::Closure error_callback_; |
363 | 387 |
364 DISALLOW_COPY_AND_ASSIGN(StubClient); | 388 DISALLOW_COPY_AND_ASSIGN(StubClient); |
365 }; | 389 }; |
366 | 390 |
367 class StubClientObserver { | 391 class StubClientObserver { |
368 public: | 392 public: |
369 StubClientObserver() | 393 StubClientObserver() |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 source()->SetSolidColor(SK_ColorGREEN); | 823 source()->SetSolidColor(SK_ColorGREEN); |
800 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 824 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
801 source()->SetSolidColor(SK_ColorRED); | 825 source()->SetSolidColor(SK_ColorRED); |
802 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 826 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
803 | 827 |
804 device()->StopAndDeAllocate(); | 828 device()->StopAndDeAllocate(); |
805 } | 829 } |
806 | 830 |
807 } // namespace | 831 } // namespace |
808 } // namespace content | 832 } // namespace content |
OLD | NEW |