| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 369 } |
| 370 | 370 |
| 371 // Trampoline method to workaround GMOCK problems with std::unique_ptr<>. | 371 // Trampoline method to workaround GMOCK problems with std::unique_ptr<>. |
| 372 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 372 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, |
| 373 const media::VideoCaptureFormat& format, | 373 const media::VideoCaptureFormat& format, |
| 374 base::TimeTicks reference_time, | 374 base::TimeTicks reference_time, |
| 375 base::TimeDelta timestamp) override { | 375 base::TimeDelta timestamp) override { |
| 376 DoOnIncomingCapturedBuffer(); | 376 DoOnIncomingCapturedBuffer(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void OnIncomingCapturedVideoFrame( | 379 void OnIncomingCapturedBufferExt( |
| 380 std::unique_ptr<Buffer> buffer, | 380 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, |
| 381 scoped_refptr<media::VideoFrame> frame) override { | 381 const media::VideoCaptureFormat& format, |
| 382 EXPECT_FALSE(frame->visible_rect().IsEmpty()); | 382 base::TimeTicks reference_time, |
| 383 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame->format()); | 383 base::TimeDelta timestamp, |
| 384 double frame_rate = 0; | 384 gfx::Rect visible_rect, |
| 385 EXPECT_TRUE( | 385 const media::VideoFrameMetadata& additional_metadata) override { |
| 386 frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 386 EXPECT_FALSE(visible_rect.IsEmpty()); |
| 387 &frame_rate)); | 387 EXPECT_EQ(media::PIXEL_FORMAT_I420, format.pixel_format); |
| 388 EXPECT_EQ(kTestFramesPerSecond, frame_rate); | 388 EXPECT_EQ(kTestFramesPerSecond, format.frame_rate); |
| 389 | 389 |
| 390 // TODO(miu): We just look at the center pixel presently, because if the | 390 // TODO(miu): We just look at the center pixel presently, because if the |
| 391 // analysis is too slow, the backlog of frames will grow without bound and | 391 // analysis is too slow, the backlog of frames will grow without bound and |
| 392 // trouble erupts. http://crbug.com/174519 | 392 // trouble erupts. http://crbug.com/174519 |
| 393 using media::VideoFrame; | 393 using media::VideoFrame; |
| 394 const gfx::Point center = frame->visible_rect().CenterPoint(); | 394 auto frame = VideoFrame::WrapExternalSharedMemory( |
| 395 media::PIXEL_FORMAT_I420, format.frame_size, visible_rect, |
| 396 format.frame_size, static_cast<uint8_t*>(buffer->data()), |
| 397 buffer->mapped_size(), base::SharedMemory::NULLHandle(), 0u, |
| 398 base::TimeDelta()); |
| 399 const gfx::Point center = visible_rect.CenterPoint(); |
| 395 const int center_offset_y = | 400 const int center_offset_y = |
| 396 (frame->stride(VideoFrame::kYPlane) * center.y()) + center.x(); | 401 (frame->stride(VideoFrame::kYPlane) * center.y()) + center.x(); |
| 397 const int center_offset_uv = | 402 const int center_offset_uv = |
| 398 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + | 403 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + |
| 399 (center.x() / 2); | 404 (center.x() / 2); |
| 400 report_callback_.Run( | 405 report_callback_.Run( |
| 401 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], | 406 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], |
| 402 frame->data(VideoFrame::kUPlane)[center_offset_uv], | 407 frame->data(VideoFrame::kUPlane)[center_offset_uv], |
| 403 frame->data(VideoFrame::kVPlane)[center_offset_uv]), | 408 frame->data(VideoFrame::kVPlane)[center_offset_uv]), |
| 404 frame->visible_rect().size()); | 409 frame->visible_rect().size()); |
| 405 } | 410 } |
| 406 | 411 |
| 407 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 412 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> |
| 408 ResurrectLastOutputBuffer(const gfx::Size& dimensions, | 413 ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
| 409 media::VideoPixelFormat format, | 414 media::VideoPixelFormat format, |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 for (int i = 0; i < 3; ++i) { | 1277 for (int i = 0; i < 3; ++i) { |
| 1273 SimulateRefreshFrameRequest(); | 1278 SimulateRefreshFrameRequest(); |
| 1274 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 1279 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
| 1275 } | 1280 } |
| 1276 | 1281 |
| 1277 device()->StopAndDeAllocate(); | 1282 device()->StopAndDeAllocate(); |
| 1278 } | 1283 } |
| 1279 | 1284 |
| 1280 } // namespace | 1285 } // namespace |
| 1281 } // namespace content | 1286 } // namespace content |
| OLD | NEW |