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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 263 } |
264 | 264 |
265 // Trampoline method to workaround GMOCK problems with std::unique_ptr<>. | 265 // Trampoline method to workaround GMOCK problems with std::unique_ptr<>. |
266 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 266 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, |
267 const media::VideoCaptureFormat& format, | 267 const media::VideoCaptureFormat& format, |
268 base::TimeTicks reference_time, | 268 base::TimeTicks reference_time, |
269 base::TimeDelta timestamp) override { | 269 base::TimeDelta timestamp) override { |
270 DoOnIncomingCapturedBuffer(); | 270 DoOnIncomingCapturedBuffer(); |
271 } | 271 } |
272 | 272 |
273 void OnIncomingCapturedVideoFrame( | 273 void OnIncomingCapturedBufferExt( |
274 std::unique_ptr<Buffer> buffer, | 274 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, |
275 scoped_refptr<media::VideoFrame> frame) override { | 275 const media::VideoCaptureFormat& format, |
276 EXPECT_FALSE(frame->visible_rect().IsEmpty()); | 276 base::TimeTicks reference_time, |
277 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame->format()); | 277 base::TimeDelta timestamp, |
278 double frame_rate = 0; | 278 gfx::Rect visible_rect, |
279 EXPECT_TRUE( | 279 const media::VideoFrameMetadata& additional_metadata) override { |
280 frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 280 EXPECT_FALSE(visible_rect.IsEmpty()); |
281 &frame_rate)); | 281 EXPECT_EQ(media::PIXEL_FORMAT_I420, format.pixel_format); |
282 EXPECT_EQ(kTestFramesPerSecond, frame_rate); | 282 EXPECT_EQ(kTestFramesPerSecond, format.frame_rate); |
283 | 283 |
284 // TODO(miu): We just look at the center pixel presently, because if the | 284 // TODO(miu): We just look at the center pixel presently, because if the |
285 // analysis is too slow, the backlog of frames will grow without bound and | 285 // analysis is too slow, the backlog of frames will grow without bound and |
286 // trouble erupts. http://crbug.com/174519 | 286 // trouble erupts. http://crbug.com/174519 |
287 using media::VideoFrame; | 287 using media::VideoFrame; |
288 const gfx::Point center = frame->visible_rect().CenterPoint(); | 288 auto frame = VideoFrame::WrapExternalSharedMemory( |
| 289 media::PIXEL_FORMAT_I420, format.frame_size, visible_rect, |
| 290 format.frame_size, static_cast<uint8_t*>(buffer->data()), |
| 291 buffer->mapped_size(), base::SharedMemory::NULLHandle(), 0u, |
| 292 base::TimeDelta()); |
| 293 const gfx::Point center = visible_rect.CenterPoint(); |
289 const int center_offset_y = | 294 const int center_offset_y = |
290 (frame->stride(VideoFrame::kYPlane) * center.y()) + center.x(); | 295 (frame->stride(VideoFrame::kYPlane) * center.y()) + center.x(); |
291 const int center_offset_uv = | 296 const int center_offset_uv = |
292 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + | 297 (frame->stride(VideoFrame::kUPlane) * (center.y() / 2)) + |
293 (center.x() / 2); | 298 (center.x() / 2); |
294 report_callback_.Run( | 299 report_callback_.Run( |
295 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], | 300 SkColorSetRGB(frame->data(VideoFrame::kYPlane)[center_offset_y], |
296 frame->data(VideoFrame::kUPlane)[center_offset_uv], | 301 frame->data(VideoFrame::kUPlane)[center_offset_uv], |
297 frame->data(VideoFrame::kVPlane)[center_offset_uv]), | 302 frame->data(VideoFrame::kVPlane)[center_offset_uv]), |
298 frame->visible_rect().size()); | 303 frame->visible_rect().size()); |
299 } | 304 } |
300 | 305 |
301 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 306 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> |
302 ResurrectLastOutputBuffer(const gfx::Size& dimensions, | 307 ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
303 media::VideoPixelFormat format, | 308 media::VideoPixelFormat format, |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 for (int i = 0; i < 3; ++i) { | 1054 for (int i = 0; i < 3; ++i) { |
1050 SimulateRefreshFrameRequest(); | 1055 SimulateRefreshFrameRequest(); |
1051 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 1056 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
1052 } | 1057 } |
1053 | 1058 |
1054 device()->StopAndDeAllocate(); | 1059 device()->StopAndDeAllocate(); |
1055 } | 1060 } |
1056 | 1061 |
1057 } // namespace | 1062 } // namespace |
1058 } // namespace content | 1063 } // namespace content |
OLD | NEW |