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" | 7 #include "media/base/video_frame.h" |
8 #include "media/mojo/common/media_type_converters.h" | 8 #include "media/mojo/common/media_type_converters.h" |
9 #include "services/video_capture/device_media_to_mojo_adapter.h" | 9 #include "services/video_capture/device_media_to_mojo_adapter.h" |
10 #include "services/video_capture/public/interfaces/device_factory.mojom.h" | 10 #include "services/video_capture/public/interfaces/device_factory.mojom.h" |
11 #include "services/video_capture/test/fake_device_test.h" | 11 #include "services/video_capture/test/fake_device_test.h" |
12 #include "services/video_capture/test/mock_receiver.h" | 12 #include "services/video_capture/test/mock_receiver.h" |
13 | 13 |
14 using testing::_; | 14 using testing::_; |
15 using testing::AtLeast; | |
16 using testing::Invoke; | 15 using testing::Invoke; |
17 using testing::InvokeWithoutArgs; | 16 using testing::InvokeWithoutArgs; |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 struct FrameInfo { | 20 struct FrameInfo { |
22 gfx::Size size; | 21 gfx::Size size; |
23 media::VideoPixelFormat pixel_format; | 22 media::VideoPixelFormat pixel_format; |
24 media::VideoPixelStorage storage_type; | 23 media::VideoFrame::StorageType storage_type; |
25 base::TimeDelta timestamp; | 24 base::TimeDelta timestamp; |
26 }; | 25 }; |
27 | 26 |
28 } // anonymous namespace | 27 } // anonymous namespace |
29 | 28 |
30 namespace video_capture { | 29 namespace video_capture { |
31 | 30 |
32 // This alias ensures test output is easily attributed to this service's tests. | 31 // This alias ensures test output is easily attributed to this service's tests. |
33 // TODO(rockot/chfremer): Consider just renaming the type. | 32 // TODO(rockot/chfremer): Consider just renaming the type. |
34 using FakeVideoCaptureDeviceTest = FakeDeviceTest; | 33 using FakeVideoCaptureDeviceTest = FakeDeviceTest; |
35 | 34 |
36 TEST_F(FakeVideoCaptureDeviceTest, FrameCallbacksArrive) { | 35 TEST_F(FakeVideoCaptureDeviceTest, DISABLED_FrameCallbacksArrive) { |
37 base::RunLoop wait_loop; | 36 base::RunLoop wait_loop; |
38 // Constants must be static as a workaround | 37 // These two constants must be static as a workaround |
39 // for a MSVC++ bug about lambda captures, see the discussion at | 38 // for a MSVC++ bug about lambda captures, see the discussion at |
40 // https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-
3b13e7909d5f | 39 // https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-
3b13e7909d5f |
41 static const int kNumFramesToWaitFor = 3; | 40 static const int kNumFramesToWaitFor = 3; |
42 int num_frames_arrived = 0; | 41 int num_frames_arrived = 0; |
43 mojom::ReceiverPtr receiver_proxy; | 42 mojom::ReceiverPtr receiver_proxy; |
44 MockReceiver receiver(mojo::MakeRequest(&receiver_proxy)); | 43 MockReceiver receiver(mojo::MakeRequest(&receiver_proxy)); |
45 EXPECT_CALL(receiver, DoOnNewBufferHandle(_, _)).Times(AtLeast(1)); | 44 EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_)) |
46 EXPECT_CALL(receiver, DoOnFrameReadyInBuffer(_, _, _, _)) | 45 .WillRepeatedly(InvokeWithoutArgs( |
47 .WillRepeatedly(InvokeWithoutArgs([&wait_loop, &num_frames_arrived]() { | 46 [&wait_loop, &num_frames_arrived]() { |
48 num_frames_arrived += 1; | 47 num_frames_arrived += 1; |
49 if (num_frames_arrived >= kNumFramesToWaitFor) { | 48 if (num_frames_arrived >= kNumFramesToWaitFor) { |
50 wait_loop.Quit(); | 49 wait_loop.Quit(); |
51 } | 50 } |
52 })); | 51 })); |
53 | 52 |
54 fake_device_proxy_->Start(requestable_settings_, std::move(receiver_proxy)); | 53 fake_device_proxy_->Start(requestable_settings_, std::move(receiver_proxy)); |
55 wait_loop.Run(); | 54 wait_loop.Run(); |
56 } | 55 } |
57 | 56 |
58 // Tests that frames received from a fake capture device match the requested | 57 // Tests that frames received from a fake capture device match the requested |
59 // format and have increasing timestamps. | 58 // format and have increasing timestamps. |
60 TEST_F(FakeVideoCaptureDeviceTest, ReceiveFramesFromFakeCaptureDevice) { | 59 TEST_F(FakeVideoCaptureDeviceTest, |
| 60 DISABLED_ReceiveFramesFromFakeCaptureDevice) { |
61 base::RunLoop wait_loop; | 61 base::RunLoop wait_loop; |
62 mojom::ReceiverPtr receiver_proxy; | 62 mojom::ReceiverPtr receiver_proxy; |
63 // Constants must be static as a workaround | 63 // These two constants must be static as a workaround |
64 // for a MSVC++ bug about lambda captures, see the discussion at | 64 // for a MSVC++ bug about lambda captures, see the discussion at |
65 // https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-
3b13e7909d5f | 65 // https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-
3b13e7909d5f |
66 static const int num_frames_to_receive = 2; | 66 static const int num_frames_to_receive = 2; |
67 FrameInfo received_frame_infos[num_frames_to_receive]; | 67 FrameInfo received_frame_infos[num_frames_to_receive]; |
68 int received_frame_count = 0; | 68 int received_frame_count = 0; |
69 MockReceiver receiver(mojo::MakeRequest(&receiver_proxy)); | 69 MockReceiver receiver(mojo::MakeRequest(&receiver_proxy)); |
70 EXPECT_CALL(receiver, DoOnNewBufferHandle(_, _)).Times(AtLeast(1)); | 70 EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_)) |
71 EXPECT_CALL(receiver, DoOnFrameReadyInBuffer(_, _, _, _)) | 71 .WillRepeatedly(Invoke( |
72 .WillRepeatedly( | 72 [&received_frame_infos, &received_frame_count, &wait_loop] |
73 Invoke([&received_frame_infos, &received_frame_count, &wait_loop]( | 73 (const media::mojom::VideoFramePtr* frame) { |
74 int32_t buffer_id, int32_t frame_feedback_id, | |
75 mojom::ScopedAccessPermissionPtr* access_permission, | |
76 media::mojom::VideoFrameInfoPtr* frame_info) { | |
77 if (received_frame_count >= num_frames_to_receive) | 74 if (received_frame_count >= num_frames_to_receive) |
78 return; | 75 return; |
79 auto& received_frame_info = | 76 auto video_frame = frame->To<scoped_refptr<media::VideoFrame>>(); |
80 received_frame_infos[received_frame_count]; | 77 auto& frame_info = received_frame_infos[received_frame_count]; |
81 received_frame_info.pixel_format = (*frame_info)->pixel_format; | 78 frame_info.pixel_format = video_frame->format(); |
82 received_frame_info.storage_type = (*frame_info)->storage_type; | 79 frame_info.storage_type = video_frame->storage_type(); |
83 received_frame_info.size = (*frame_info)->coded_size; | 80 frame_info.size = video_frame->natural_size(); |
84 received_frame_info.timestamp = (*frame_info)->timestamp; | 81 frame_info.timestamp = video_frame->timestamp(); |
85 received_frame_count += 1; | 82 received_frame_count += 1; |
86 if (received_frame_count == num_frames_to_receive) | 83 if (received_frame_count == num_frames_to_receive) |
87 wait_loop.Quit(); | 84 wait_loop.Quit(); |
88 })); | 85 })); |
89 | 86 |
90 fake_device_proxy_->Start(requestable_settings_, std::move(receiver_proxy)); | 87 fake_device_proxy_->Start(requestable_settings_, std::move(receiver_proxy)); |
91 | 88 |
92 wait_loop.Run(); | 89 wait_loop.Run(); |
93 | 90 |
94 base::TimeDelta previous_timestamp; | 91 base::TimeDelta previous_timestamp; |
95 for (int i = 0; i < num_frames_to_receive; i++) { | 92 for (int i = 0; i < num_frames_to_receive; i++) { |
96 auto& frame_info = received_frame_infos[i]; | 93 auto& frame_info = received_frame_infos[i]; |
97 // Service is expected to always output I420 | 94 // Service is expected to always output I420 |
98 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame_info.pixel_format); | 95 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame_info.pixel_format); |
99 // Service is expected to always use PIXEL_STORAGE_CPU | 96 // Service is expected to always use STORAGE_MOJO_SHARED_BUFFER |
100 EXPECT_EQ(media::PIXEL_STORAGE_CPU, frame_info.storage_type); | 97 EXPECT_EQ(media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER, |
101 EXPECT_EQ(requestable_settings_.requested_format.frame_size, | 98 frame_info.storage_type); |
102 frame_info.size); | |
103 // Timestamps are expected to increase | 99 // Timestamps are expected to increase |
104 if (i > 0) | 100 if (i > 0) |
105 EXPECT_GT(frame_info.timestamp, previous_timestamp); | 101 EXPECT_GT(frame_info.timestamp, previous_timestamp); |
106 previous_timestamp = frame_info.timestamp; | 102 previous_timestamp = frame_info.timestamp; |
107 } | 103 } |
108 } | 104 } |
109 | 105 |
110 // Tests that buffers get reused when receiving more frames than the maximum | |
111 // number of buffers in the pool. | |
112 TEST_F(FakeVideoCaptureDeviceTest, BuffersGetReused) { | |
113 base::RunLoop wait_loop; | |
114 const int kMaxBufferPoolBuffers = | |
115 DeviceMediaToMojoAdapter::max_buffer_pool_buffer_count(); | |
116 // Constants must be static as a workaround | |
117 // for a MSVC++ bug about lambda captures, see the discussion at | |
118 // https://social.msdn.microsoft.com/Forums/SqlServer/4abf18bd-4ae4-4c72-ba3e-
3b13e7909d5f | |
119 static const int kNumFramesToWaitFor = kMaxBufferPoolBuffers + 3; | |
120 int num_buffers_created = 0; | |
121 int num_frames_arrived = 0; | |
122 mojom::ReceiverPtr receiver_proxy; | |
123 MockReceiver receiver(mojo::MakeRequest(&receiver_proxy)); | |
124 EXPECT_CALL(receiver, DoOnNewBufferHandle(_, _)) | |
125 .WillRepeatedly(InvokeWithoutArgs( | |
126 [&num_buffers_created]() { num_buffers_created++; })); | |
127 EXPECT_CALL(receiver, DoOnFrameReadyInBuffer(_, _, _, _)) | |
128 .WillRepeatedly(InvokeWithoutArgs([&wait_loop, &num_frames_arrived]() { | |
129 if (++num_frames_arrived >= kNumFramesToWaitFor) { | |
130 wait_loop.Quit(); | |
131 } | |
132 })); | |
133 | |
134 fake_device_proxy_->Start(requestable_settings_, std::move(receiver_proxy)); | |
135 wait_loop.Run(); | |
136 | |
137 ASSERT_LT(num_buffers_created, num_frames_arrived); | |
138 ASSERT_LE(num_buffers_created, kMaxBufferPoolBuffers); | |
139 } | |
140 | |
141 } // namespace video_capture | 106 } // namespace video_capture |
OLD | NEW |