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" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
14 #include "content/browser/media/capture/video_capture_oracle.h" | 14 #include "content/browser/media/capture/video_capture_oracle.h" |
15 #include "content/browser/media/capture/web_contents_capture_util.h" | 15 #include "content/browser/media/capture/web_contents_capture_util.h" |
16 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 16 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
17 #include "content/browser/renderer_host/render_view_host_factory.h" | 17 #include "content/browser/renderer_host/render_view_host_factory.h" |
18 #include "content/browser/renderer_host/render_widget_host_impl.h" | 18 #include "content/browser/renderer_host/render_widget_host_impl.h" |
19 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 19 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
22 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
23 #include "content/public/test/test_browser_context.h" | 23 #include "content/public/test/test_browser_context.h" |
24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
26 #include "content/test/test_render_view_host.h" | 26 #include "content/test/test_render_view_host.h" |
27 #include "content/test/test_web_contents.h" | 27 #include "content/test/test_web_contents.h" |
| 28 #include "media/base/video_frame.h" |
28 #include "media/base/video_util.h" | 29 #include "media/base/video_util.h" |
29 #include "media/base/yuv_convert.h" | 30 #include "media/base/yuv_convert.h" |
30 #include "media/video/capture/video_capture_types.h" | 31 #include "media/video/capture/video_capture_types.h" |
31 #include "skia/ext/platform_canvas.h" | 32 #include "skia/ext/platform_canvas.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "third_party/skia/include/core/SkColor.h" | 34 #include "third_party/skia/include/core/SkColor.h" |
34 | 35 |
35 namespace content { | 36 namespace content { |
36 namespace { | 37 namespace { |
37 | 38 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 const base::Closure& error_callback) | 312 const base::Closure& error_callback) |
312 : color_callback_(color_callback), | 313 : color_callback_(color_callback), |
313 error_callback_(error_callback) { | 314 error_callback_(error_callback) { |
314 buffer_pool_ = new VideoCaptureBufferPool(2); | 315 buffer_pool_ = new VideoCaptureBufferPool(2); |
315 } | 316 } |
316 virtual ~StubClient() {} | 317 virtual ~StubClient() {} |
317 | 318 |
318 virtual scoped_refptr<media::VideoCaptureDevice::Client::Buffer> | 319 virtual scoped_refptr<media::VideoCaptureDevice::Client::Buffer> |
319 ReserveOutputBuffer(media::VideoFrame::Format format, | 320 ReserveOutputBuffer(media::VideoFrame::Format format, |
320 const gfx::Size& dimensions) OVERRIDE { | 321 const gfx::Size& dimensions) OVERRIDE { |
| 322 CHECK_EQ(format, media::VideoFrame::I420); |
321 const size_t frame_bytes = | 323 const size_t frame_bytes = |
322 media::VideoFrame::AllocationSize(format, dimensions); | 324 media::VideoFrame::AllocationSize(media::VideoFrame::I420, dimensions); |
323 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. | 325 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. |
324 int buffer_id = | 326 int buffer_id = |
325 buffer_pool_->ReserveForProducer(frame_bytes, &buffer_id_to_drop); | 327 buffer_pool_->ReserveForProducer(frame_bytes, &buffer_id_to_drop); |
326 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 328 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
327 return NULL; | 329 return NULL; |
328 void* data; | 330 void* data; |
329 size_t size; | 331 size_t size; |
330 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); | 332 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); |
331 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( | 333 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>( |
332 new PoolBuffer(buffer_pool_, buffer_id, data, size)); | 334 new PoolBuffer(buffer_pool_, buffer_id, data, size)); |
333 } | 335 } |
334 | 336 |
335 virtual void OnIncomingCapturedFrame( | 337 virtual void OnIncomingCapturedData( |
336 const uint8* data, | 338 const uint8* data, |
337 int length, | 339 int length, |
338 base::TimeTicks timestamp, | 340 const media::VideoCaptureFormat& frame_format, |
339 int rotation, | 341 int rotation, |
340 const media::VideoCaptureFormat& frame_format) OVERRIDE { | 342 base::TimeTicks timestamp) OVERRIDE { |
341 FAIL(); | 343 FAIL(); |
342 } | 344 } |
343 | 345 |
344 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, | 346 virtual void OnIncomingCapturedVideoFrame( |
345 media::VideoFrame::Format format, | 347 const scoped_refptr<Buffer>& buffer, |
346 const gfx::Size& dimensions, | 348 const media::VideoCaptureFormat& buffer_format, |
347 base::TimeTicks timestamp, | 349 const scoped_refptr<media::VideoFrame>& frame, |
348 int frame_rate) OVERRIDE { | 350 base::TimeTicks timestamp) OVERRIDE { |
349 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), dimensions); | 351 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), buffer_format.frame_size); |
350 EXPECT_EQ(media::VideoFrame::I420, format); | 352 EXPECT_EQ(media::PIXEL_FORMAT_I420, buffer_format.pixel_format); |
| 353 EXPECT_EQ(media::VideoFrame::I420, frame->format()); |
351 uint8 yuv[3]; | 354 uint8 yuv[3]; |
352 size_t offset = 0; | 355 for (int plane = 0; plane < 3; ++plane) |
353 for (int plane = 0; plane < 3; ++plane) { | 356 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); | |
357 } | |
358 // TODO(nick): We just look at the first pixel presently, because if | 357 // TODO(nick): We just look at the first pixel presently, because if |
359 // the analysis is too slow, the backlog of frames will grow without bound | 358 // the analysis is too slow, the backlog of frames will grow without bound |
360 // and trouble erupts. http://crbug.com/174519 | 359 // and trouble erupts. http://crbug.com/174519 |
361 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); | 360 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); |
362 } | 361 } |
363 | 362 |
364 virtual void OnError(const std::string& reason) OVERRIDE { | 363 virtual void OnError(const std::string& reason) OVERRIDE { |
365 error_callback_.Run(); | 364 error_callback_.Run(); |
366 } | 365 } |
367 | 366 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 source()->SetSolidColor(SK_ColorGREEN); | 805 source()->SetSolidColor(SK_ColorGREEN); |
807 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 806 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
808 source()->SetSolidColor(SK_ColorRED); | 807 source()->SetSolidColor(SK_ColorRED); |
809 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 808 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
810 | 809 |
811 device()->StopAndDeAllocate(); | 810 device()->StopAndDeAllocate(); |
812 } | 811 } |
813 | 812 |
814 } // namespace | 813 } // namespace |
815 } // namespace content | 814 } // namespace content |
OLD | NEW |