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