OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "media/base/video_frame.h" |
| 8 #include "media/mojo/common/media_type_converters.h" |
7 #include "services/video_capture/fake_device_test.h" | 9 #include "services/video_capture/fake_device_test.h" |
8 #include "services/video_capture/mock_video_frame_receiver.h" | 10 #include "services/video_capture/mock_video_frame_receiver.h" |
9 #include "services/video_capture/public/cpp/video_capture_settings.h" | 11 #include "services/video_capture/public/cpp/video_capture_settings.h" |
10 #include "services/video_capture/public/interfaces/video_capture_device_factory.
mojom.h" | 12 #include "services/video_capture/public/interfaces/video_capture_device_factory.
mojom.h" |
11 #include "services/video_capture/video_capture_service_test.h" | 13 #include "services/video_capture/video_capture_service_test.h" |
12 | 14 |
13 using testing::_; | 15 using testing::_; |
| 16 using testing::Invoke; |
14 using testing::InvokeWithoutArgs; | 17 using testing::InvokeWithoutArgs; |
15 | 18 |
| 19 namespace { |
| 20 |
| 21 struct FrameInfo { |
| 22 gfx::Size size; |
| 23 media::VideoPixelFormat pixel_format; |
| 24 media::VideoFrame::StorageType storage_type; |
| 25 bool is_mappable; |
| 26 base::TimeDelta timestamp; |
| 27 }; |
| 28 |
| 29 } // anonymous namespace |
| 30 |
16 namespace video_capture { | 31 namespace video_capture { |
17 | 32 |
18 TEST_F(FakeDeviceTest, FrameCallbacksArrive) { | 33 TEST_F(FakeDeviceTest, FrameCallbacksArrive) { |
19 VideoCaptureSettings arbitrary_requested_settings; | 34 VideoCaptureSettings arbitrary_requested_settings; |
20 arbitrary_requested_settings.format.frame_size.SetSize(640, 480); | 35 arbitrary_requested_settings.format.frame_size.SetSize(640, 480); |
21 arbitrary_requested_settings.format.frame_rate = 15; | 36 arbitrary_requested_settings.format.frame_rate = 15; |
22 arbitrary_requested_settings.resolution_change_policy = | 37 arbitrary_requested_settings.resolution_change_policy = |
23 media::RESOLUTION_POLICY_FIXED_RESOLUTION; | 38 media::RESOLUTION_POLICY_FIXED_RESOLUTION; |
24 arbitrary_requested_settings.power_line_frequency = | 39 arbitrary_requested_settings.power_line_frequency = |
25 media::PowerLineFrequency::FREQUENCY_DEFAULT; | 40 media::PowerLineFrequency::FREQUENCY_DEFAULT; |
(...skipping 10 matching lines...) Expand all Loading... |
36 if (num_frames_arrived >= kNumFramesToWaitFor) { | 51 if (num_frames_arrived >= kNumFramesToWaitFor) { |
37 wait_loop.Quit(); | 52 wait_loop.Quit(); |
38 } | 53 } |
39 })); | 54 })); |
40 | 55 |
41 fake_device_proxy_->Start(arbitrary_requested_settings, | 56 fake_device_proxy_->Start(arbitrary_requested_settings, |
42 std::move(receiver_proxy)); | 57 std::move(receiver_proxy)); |
43 wait_loop.Run(); | 58 wait_loop.Run(); |
44 } | 59 } |
45 | 60 |
| 61 // Tests that frames received from a fake capture device match the requested |
| 62 // format and have increasing timestamps. |
| 63 TEST_F(FakeDeviceTest, ReceiveFramesFromFakeCaptureDevice) { |
| 64 base::RunLoop wait_loop; |
| 65 mojom::VideoFrameReceiverPtr receiver_proxy; |
| 66 constexpr int num_frames_to_receive = 2; |
| 67 FrameInfo received_frame_infos[num_frames_to_receive]; |
| 68 int received_frame_count = 0; |
| 69 MockVideoFrameReceiver receiver(mojo::GetProxy(&receiver_proxy)); |
| 70 EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_)) |
| 71 .WillRepeatedly( |
| 72 Invoke([&received_frame_infos, &received_frame_count, |
| 73 &num_frames_to_receive, &wait_loop]( |
| 74 const media::mojom::VideoFramePtr* frame) { |
| 75 if (received_frame_count >= num_frames_to_receive) |
| 76 return; |
| 77 auto video_frame = frame->To<scoped_refptr<media::VideoFrame>>(); |
| 78 auto& frame_info = received_frame_infos[received_frame_count]; |
| 79 frame_info.pixel_format = video_frame->format(); |
| 80 frame_info.storage_type = video_frame->storage_type(); |
| 81 frame_info.is_mappable = video_frame->IsMappable(); |
| 82 frame_info.size = video_frame->natural_size(); |
| 83 frame_info.timestamp = video_frame->timestamp(); |
| 84 received_frame_count += 1; |
| 85 if (received_frame_count == num_frames_to_receive) |
| 86 wait_loop.Quit(); |
| 87 })); |
| 88 |
| 89 fake_device_proxy_->Start( |
| 90 requestable_settings_, std::move(receiver_proxy)); |
| 91 |
| 92 wait_loop.Run(); |
| 93 |
| 94 base::TimeDelta previous_timestamp; |
| 95 for (int i = 0; i < num_frames_to_receive; i++) { |
| 96 auto& frame_info = received_frame_infos[i]; |
| 97 // Service is expected to always output I420 |
| 98 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame_info.pixel_format); |
| 99 // Service is expected to always use STORAGE_MOJO_SHARED_BUFFER |
| 100 EXPECT_EQ(media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER, |
| 101 frame_info.storage_type); |
| 102 EXPECT_TRUE(frame_info.is_mappable); |
| 103 EXPECT_EQ(requestable_settings_.format.frame_size, |
| 104 frame_info.size); |
| 105 // Timestamps are expected to increase |
| 106 if (i > 0) |
| 107 EXPECT_GT(frame_info.timestamp, previous_timestamp); |
| 108 previous_timestamp = frame_info.timestamp; |
| 109 } |
| 110 } |
| 111 |
46 } // namespace video_capture | 112 } // namespace video_capture |
OLD | NEW |