OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "content/browser/browser_main_loop.h" | 8 #include "content/browser/browser_main_loop.h" |
9 #include "content/browser/renderer_host/media/media_stream_manager.h" | 9 #include "content/browser/renderer_host/media/media_stream_manager.h" |
10 #include "content/browser/renderer_host/media/video_capture_manager.h" | 10 #include "content/browser/renderer_host/media/video_capture_manager.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 MOCK_METHOD2(Closed, void(MediaStreamType, int)); | 57 MOCK_METHOD2(Closed, void(MediaStreamType, int)); |
58 MOCK_METHOD2(Aborted, void(MediaStreamType, int)); | 58 MOCK_METHOD2(Aborted, void(MediaStreamType, int)); |
59 }; | 59 }; |
60 | 60 |
61 struct TestParams { | 61 struct TestParams { |
62 std::string fake_device_factory_config_string; | 62 std::string fake_device_factory_config_string; |
63 size_t device_index_to_use; | 63 size_t device_index_to_use; |
64 media::VideoPixelFormat pixel_format_to_use; | 64 media::VideoPixelFormat pixel_format_to_use; |
65 gfx::Size resolution_to_use; | 65 gfx::Size resolution_to_use; |
66 float frame_rate_to_use; | 66 float frame_rate_to_use; |
67 bool exercise_accelerated_jpeg_decoding; | |
68 }; | 67 }; |
69 | 68 |
70 struct FrameInfo { | 69 struct FrameInfo { |
71 gfx::Size size; | 70 gfx::Size size; |
72 media::VideoPixelFormat pixel_format; | 71 media::VideoPixelFormat pixel_format; |
73 media::VideoPixelStorage storage_type; | 72 media::VideoPixelStorage storage_type; |
74 base::TimeDelta timestamp; | 73 base::TimeDelta timestamp; |
75 }; | 74 }; |
76 | 75 |
77 class VideoCaptureBrowserTest | 76 class VideoCaptureBrowserTest |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 109 |
111 video_capture_manager_->Close(session_id_); | 110 video_capture_manager_->Close(session_id_); |
112 } | 111 } |
113 | 112 |
114 protected: | 113 protected: |
115 void SetUpCommandLine(base::CommandLine* command_line) override { | 114 void SetUpCommandLine(base::CommandLine* command_line) override { |
116 command_line->AppendSwitchASCII( | 115 command_line->AppendSwitchASCII( |
117 switches::kUseFakeDeviceForMediaStream, | 116 switches::kUseFakeDeviceForMediaStream, |
118 GetParam().fake_device_factory_config_string); | 117 GetParam().fake_device_factory_config_string); |
119 command_line->AppendSwitch(switches::kUseFakeUIForMediaStream); | 118 command_line->AppendSwitch(switches::kUseFakeUIForMediaStream); |
120 if (GetParam().exercise_accelerated_jpeg_decoding) { | |
121 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
122 switches::kUseFakeJpegDecodeAccelerator); | |
123 } else { | |
124 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
125 switches::kDisableAcceleratedMjpegDecode); | |
126 } | |
127 } | 119 } |
128 | 120 |
129 // This cannot be part of an override of SetUp(), because at the time when | 121 // This cannot be part of an override of SetUp(), because at the time when |
130 // SetUp() is invoked, the BrowserMainLoop does not exist yet. | 122 // SetUp() is invoked, the BrowserMainLoop does not exist yet. |
131 void SetUpRequiringBrowserMainLoopOnMainThread() { | 123 void SetUpRequiringBrowserMainLoopOnMainThread() { |
132 BrowserMainLoop* browser_main_loop = BrowserMainLoop::GetInstance(); | 124 BrowserMainLoop* browser_main_loop = BrowserMainLoop::GetInstance(); |
133 ASSERT_TRUE(browser_main_loop); | 125 ASSERT_TRUE(browser_main_loop); |
134 media_stream_manager_ = browser_main_loop->media_stream_manager(); | 126 media_stream_manager_ = browser_main_loop->media_stream_manager(); |
135 ASSERT_TRUE(media_stream_manager_); | 127 ASSERT_TRUE(media_stream_manager_); |
136 } | 128 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 base::Bind(&VideoCaptureBrowserTest::SetUpAndStartCaptureDeviceOnIOThread, | 181 base::Bind(&VideoCaptureBrowserTest::SetUpAndStartCaptureDeviceOnIOThread, |
190 base::Unretained(this), std::move(after_start_continuation))); | 182 base::Unretained(this), std::move(after_start_continuation))); |
191 run_loop.Run(); | 183 run_loop.Run(); |
192 } | 184 } |
193 | 185 |
194 IN_PROC_BROWSER_TEST_P(VideoCaptureBrowserTest, | 186 IN_PROC_BROWSER_TEST_P(VideoCaptureBrowserTest, |
195 ReceiveFramesFromFakeCaptureDevice) { | 187 ReceiveFramesFromFakeCaptureDevice) { |
196 SetUpRequiringBrowserMainLoopOnMainThread(); | 188 SetUpRequiringBrowserMainLoopOnMainThread(); |
197 | 189 |
198 std::vector<FrameInfo> received_frame_infos; | 190 std::vector<FrameInfo> received_frame_infos; |
199 static const size_t kMinFramesToReceive = 3; | 191 static const size_t kNumFramesToReceive = 3; |
200 static const size_t kMaxFramesToReceive = 300; | |
201 base::RunLoop run_loop; | 192 base::RunLoop run_loop; |
202 | 193 |
203 auto quit_run_loop_on_current_thread_cb = | 194 auto quit_run_loop_on_current_thread_cb = |
204 media::BindToCurrentLoop(run_loop.QuitClosure()); | 195 media::BindToCurrentLoop(run_loop.QuitClosure()); |
205 auto finish_test_cb = | 196 auto finish_test_cb = |
206 base::Bind(&VideoCaptureBrowserTest::TearDownCaptureDeviceOnIOThread, | 197 base::Bind(&VideoCaptureBrowserTest::TearDownCaptureDeviceOnIOThread, |
207 base::Unretained(this), | 198 base::Unretained(this), |
208 std::move(quit_run_loop_on_current_thread_cb), true); | 199 std::move(quit_run_loop_on_current_thread_cb), true); |
209 | 200 |
210 bool must_wait_for_gpu_decode_to_start = false; | |
211 if (GetParam().exercise_accelerated_jpeg_decoding) { | |
212 // Since the GPU jpeg decoder is created asynchronously while decoding | |
213 // in software is ongoing, we have to keep pushing frames until a message | |
214 // arrives that tells us that the GPU decoder is being used. Otherwise, | |
215 // it may happen that all test frames are decoded using the non-GPU | |
216 // decoding path before the GPU decoder has started getting used. | |
217 must_wait_for_gpu_decode_to_start = true; | |
218 EXPECT_CALL(mock_controller_event_handler_, OnStartedUsingGpuDecode(_)) | |
219 .WillOnce(InvokeWithoutArgs([&must_wait_for_gpu_decode_to_start]() { | |
220 must_wait_for_gpu_decode_to_start = false; | |
221 })); | |
222 } | |
223 EXPECT_CALL(mock_controller_event_handler_, DoOnBufferCreated(_, _, _, _)) | 201 EXPECT_CALL(mock_controller_event_handler_, DoOnBufferCreated(_, _, _, _)) |
224 .Times(AtLeast(1)); | 202 .Times(AtLeast(1)); |
225 EXPECT_CALL(mock_controller_event_handler_, OnBufferReady(_, _, _)) | 203 EXPECT_CALL(mock_controller_event_handler_, OnBufferReady(_, _, _)) |
226 .WillRepeatedly(Invoke( | 204 .WillRepeatedly( |
227 [&received_frame_infos, &must_wait_for_gpu_decode_to_start, | 205 Invoke([&received_frame_infos, &finish_test_cb]( |
228 &finish_test_cb](VideoCaptureControllerID id, int buffer_id, | 206 VideoCaptureControllerID id, int buffer_id, |
229 const media::mojom::VideoFrameInfoPtr& frame_info) { | 207 const media::mojom::VideoFrameInfoPtr& frame_info) { |
230 FrameInfo received_frame_info; | 208 FrameInfo received_frame_info; |
231 received_frame_info.pixel_format = frame_info->pixel_format; | 209 received_frame_info.pixel_format = frame_info->pixel_format; |
232 received_frame_info.storage_type = frame_info->storage_type; | 210 received_frame_info.storage_type = frame_info->storage_type; |
233 received_frame_info.size = frame_info->coded_size; | 211 received_frame_info.size = frame_info->coded_size; |
234 received_frame_info.timestamp = frame_info->timestamp; | 212 received_frame_info.timestamp = frame_info->timestamp; |
235 received_frame_infos.emplace_back(received_frame_info); | 213 received_frame_infos.emplace_back(received_frame_info); |
236 if ((received_frame_infos.size() >= kMinFramesToReceive && | 214 if (received_frame_infos.size() >= kNumFramesToReceive) { |
237 !must_wait_for_gpu_decode_to_start) || | |
238 (received_frame_infos.size() == kMaxFramesToReceive)) { | |
239 finish_test_cb.Run(); | 215 finish_test_cb.Run(); |
240 } | 216 } |
241 })); | 217 })); |
242 | 218 |
243 base::Closure do_nothing; | 219 base::Closure do_nothing; |
244 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
245 content::BrowserThread::IO, FROM_HERE, | 221 content::BrowserThread::IO, FROM_HERE, |
246 base::Bind(&VideoCaptureBrowserTest::SetUpAndStartCaptureDeviceOnIOThread, | 222 base::Bind(&VideoCaptureBrowserTest::SetUpAndStartCaptureDeviceOnIOThread, |
247 base::Unretained(this), std::move(do_nothing))); | 223 base::Unretained(this), std::move(do_nothing))); |
248 run_loop.Run(); | 224 run_loop.Run(); |
249 | 225 |
250 EXPECT_FALSE(must_wait_for_gpu_decode_to_start); | 226 EXPECT_GE(received_frame_infos.size(), kNumFramesToReceive); |
251 EXPECT_GE(received_frame_infos.size(), kMinFramesToReceive); | |
252 EXPECT_LT(received_frame_infos.size(), kMaxFramesToReceive); | |
253 base::TimeDelta previous_timestamp; | 227 base::TimeDelta previous_timestamp; |
254 bool first_frame = true; | 228 bool first_frame = true; |
255 for (const auto& frame_info : received_frame_infos) { | 229 for (const auto& frame_info : received_frame_infos) { |
256 EXPECT_EQ(GetParam().pixel_format_to_use, frame_info.pixel_format); | 230 EXPECT_EQ(GetParam().pixel_format_to_use, frame_info.pixel_format); |
257 EXPECT_EQ(media::PIXEL_STORAGE_CPU, frame_info.storage_type); | 231 EXPECT_EQ(media::PIXEL_STORAGE_CPU, frame_info.storage_type); |
258 EXPECT_EQ(GetParam().resolution_to_use, frame_info.size); | 232 EXPECT_EQ(GetParam().resolution_to_use, frame_info.size); |
259 // Timestamps are expected to increase | 233 // Timestamps are expected to increase |
260 if (!first_frame) | 234 if (!first_frame) |
261 EXPECT_GT(frame_info.timestamp, previous_timestamp); | 235 EXPECT_GT(frame_info.timestamp, previous_timestamp); |
262 first_frame = false; | 236 first_frame = false; |
263 previous_timestamp = frame_info.timestamp; | 237 previous_timestamp = frame_info.timestamp; |
264 } | 238 } |
265 } | 239 } |
266 | 240 |
267 INSTANTIATE_TEST_CASE_P( | 241 INSTANTIATE_TEST_CASE_P( |
268 , | 242 , |
269 VideoCaptureBrowserTest, | 243 VideoCaptureBrowserTest, |
270 Values(TestParams{"fps=25,device-count=2", 0, media::PIXEL_FORMAT_I420, | 244 Values(TestParams{"fps=25,device-count=2", 0, media::PIXEL_FORMAT_I420, |
271 gfx::Size(1280, 720), 25.0f, false}, | 245 gfx::Size(1280, 720), 25.0f}, |
272 // The 2nd device outputs Y16 | 246 // The 2nd device outputs Y16 |
273 TestParams{"fps=25,device-count=2", 1, media::PIXEL_FORMAT_Y16, | 247 TestParams{"fps=25,device-count=2", 1, media::PIXEL_FORMAT_Y16, |
274 gfx::Size(1280, 720), 25.0f, false}, | 248 gfx::Size(1280, 720), 25.0f}, |
275 TestParams{"fps=15,device-count=2", 1, media::PIXEL_FORMAT_Y16, | 249 TestParams{"fps=15,device-count=2", 1, media::PIXEL_FORMAT_Y16, |
276 gfx::Size(640, 480), 15.0f, false}, | 250 gfx::Size(640, 480), 15.0f}, |
277 // The 3rd device outputs MJPEG, which is converted to I420. | 251 // The 3rd device outputs MJPEG, which is converted to I420. |
278 TestParams{"fps=15,device-count=3", 2, media::PIXEL_FORMAT_I420, | 252 TestParams{"fps=15,device-count=3", 2, media::PIXEL_FORMAT_I420, |
279 gfx::Size(640, 480), 25.0f, false}, | 253 gfx::Size(640, 480), 25.0f})); |
280 TestParams{"fps=6,device-count=3", 2, media::PIXEL_FORMAT_I420, | |
281 gfx::Size(640, 480), 6.0f, true})); | |
282 | 254 |
283 } // namespace content | 255 } // namespace content |
OLD | NEW |