OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/media/media_stream_video_capturer_source.h" | 5 #include "content/renderer/media/media_stream_video_capturer_source.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/WebKit/public/web/WebHeap.h" | 25 #include "third_party/WebKit/public/web/WebHeap.h" |
26 | 26 |
27 using ::testing::_; | 27 using ::testing::_; |
28 using ::testing::InSequence; | 28 using ::testing::InSequence; |
29 using ::testing::Invoke; | 29 using ::testing::Invoke; |
30 using ::testing::WithArgs; | 30 using ::testing::WithArgs; |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 | 33 |
| 34 namespace { |
| 35 |
34 class MockVideoCapturerSource : public media::VideoCapturerSource { | 36 class MockVideoCapturerSource : public media::VideoCapturerSource { |
35 public: | 37 public: |
36 MockVideoCapturerSource() { | 38 MockVideoCapturerSource() { |
37 ON_CALL(*this, GetCurrentSupportedFormats(_, _, _, _)) | 39 ON_CALL(*this, GetCurrentSupportedFormats(_, _, _, _)) |
38 .WillByDefault(WithArgs<3>( | 40 .WillByDefault(WithArgs<3>( |
39 Invoke(this, &MockVideoCapturerSource::EnumerateDeviceFormats))); | 41 Invoke(this, &MockVideoCapturerSource::EnumerateDeviceFormats))); |
40 } | 42 } |
41 | 43 |
42 MOCK_METHOD0(RequestRefreshFrame, void()); | 44 MOCK_METHOD0(RequestRefreshFrame, void()); |
43 MOCK_METHOD4(GetCurrentSupportedFormats, | 45 MOCK_METHOD4(GetCurrentSupportedFormats, |
(...skipping 13 matching lines...) Expand all Loading... |
57 media::PIXEL_FORMAT_I420); | 59 media::PIXEL_FORMAT_I420); |
58 media::VideoCaptureFormat kFormatLarge(gfx::Size(1920, 1080), 30.0, | 60 media::VideoCaptureFormat kFormatLarge(gfx::Size(1920, 1080), 30.0, |
59 media::PIXEL_FORMAT_I420); | 61 media::PIXEL_FORMAT_I420); |
60 media::VideoCaptureFormats formats; | 62 media::VideoCaptureFormats formats; |
61 formats.push_back(kFormatSmall); | 63 formats.push_back(kFormatSmall); |
62 formats.push_back(kFormatLarge); | 64 formats.push_back(kFormatLarge); |
63 callback.Run(formats); | 65 callback.Run(formats); |
64 } | 66 } |
65 }; | 67 }; |
66 | 68 |
| 69 class FakeMediaStreamVideoSink : public MediaStreamVideoSink { |
| 70 public: |
| 71 FakeMediaStreamVideoSink(base::TimeTicks* capture_time, |
| 72 media::VideoFrameMetadata* metadata, |
| 73 base::Closure got_frame_cb) |
| 74 : capture_time_(capture_time), |
| 75 metadata_(metadata), |
| 76 got_frame_cb_(got_frame_cb) {} |
| 77 |
| 78 void ConnectToTrack(const blink::WebMediaStreamTrack& track) { |
| 79 MediaStreamVideoSink::ConnectToTrack( |
| 80 track, |
| 81 base::Bind(&FakeMediaStreamVideoSink::OnVideoFrame, |
| 82 base::Unretained(this)), |
| 83 true); |
| 84 } |
| 85 |
| 86 void DisconnectFromTrack() { MediaStreamVideoSink::DisconnectFromTrack(); } |
| 87 |
| 88 void OnVideoFrame(const scoped_refptr<media::VideoFrame>& frame, |
| 89 base::TimeTicks capture_time) { |
| 90 *capture_time_ = capture_time; |
| 91 metadata_->Clear(); |
| 92 metadata_->MergeMetadataFrom(frame->metadata()); |
| 93 base::ResetAndReturn(&got_frame_cb_).Run(); |
| 94 } |
| 95 |
| 96 private: |
| 97 base::TimeTicks* const capture_time_; |
| 98 media::VideoFrameMetadata* const metadata_; |
| 99 base::Closure got_frame_cb_; |
| 100 }; |
| 101 |
| 102 } // namespace |
| 103 |
67 class MediaStreamVideoCapturerSourceTest : public testing::Test { | 104 class MediaStreamVideoCapturerSourceTest : public testing::Test { |
68 public: | 105 public: |
69 MediaStreamVideoCapturerSourceTest() | 106 MediaStreamVideoCapturerSourceTest() |
70 : child_process_(new ChildProcess()), | 107 : child_process_(new ChildProcess()), |
71 source_(nullptr), | 108 source_(nullptr), |
72 delegate_(nullptr), | 109 delegate_(nullptr), |
73 source_stopped_(false) {} | 110 source_stopped_(false) { |
| 111 scoped_feature_list_.InitAndDisableFeature( |
| 112 features::kMediaStreamOldVideoConstraints); |
| 113 } |
74 | 114 |
75 void TearDown() override { | 115 void TearDown() override { |
76 webkit_source_.reset(); | 116 webkit_source_.reset(); |
77 blink::WebHeap::collectAllGarbageForTesting(); | 117 blink::WebHeap::collectAllGarbageForTesting(); |
78 } | 118 } |
79 | 119 |
80 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { | 120 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { |
81 std::unique_ptr<MockVideoCapturerSource> delegate( | 121 std::unique_ptr<MockVideoCapturerSource> delegate( |
82 new MockVideoCapturerSource()); | 122 new MockVideoCapturerSource()); |
83 delegate_ = delegate.get(); | 123 delegate_ = delegate.get(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // and Sources below into believing they are on the right threads. | 183 // and Sources below into believing they are on the right threads. |
144 base::MessageLoopForUI message_loop_; | 184 base::MessageLoopForUI message_loop_; |
145 std::unique_ptr<ChildProcess> child_process_; | 185 std::unique_ptr<ChildProcess> child_process_; |
146 | 186 |
147 blink::WebMediaStreamSource webkit_source_; | 187 blink::WebMediaStreamSource webkit_source_; |
148 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. | 188 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. |
149 MockVideoCapturerSource* delegate_; // owned by |source|. | 189 MockVideoCapturerSource* delegate_; // owned by |source|. |
150 blink::WebString webkit_source_id_; | 190 blink::WebString webkit_source_id_; |
151 bool source_stopped_; | 191 bool source_stopped_; |
152 MockConstraintFactory constraint_factory_; | 192 MockConstraintFactory constraint_factory_; |
| 193 base::test::ScopedFeatureList scoped_feature_list_; |
153 }; | 194 }; |
154 | 195 |
155 // This test does not apply with spec-compliant constraints. | 196 TEST_F(MediaStreamVideoCapturerSourceTest, StartAndStop) { |
156 // TODO(guidou): Remove this test. http://crbug.com/706408 | 197 std::unique_ptr<MockVideoCapturerSource> delegate( |
157 TEST_F(MediaStreamVideoCapturerSourceTest, | 198 new MockVideoCapturerSource()); |
158 TabCaptureFixedResolutionByDefaultOldConstraints) { | 199 delegate_ = delegate.get(); |
159 base::test::ScopedFeatureList scoped_feature_list; | 200 EXPECT_CALL(*delegate_, GetPreferredFormats()); |
160 scoped_feature_list.InitAndEnableFeature( | 201 source_ = new MediaStreamVideoCapturerSource( |
161 features::kMediaStreamOldVideoConstraints); | 202 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, |
| 203 base::Unretained(this)), |
| 204 std::move(delegate)); |
| 205 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), |
| 206 blink::WebMediaStreamSource::TypeVideo, |
| 207 blink::WebString::fromASCII("dummy_source_name"), |
| 208 false /* remote */); |
| 209 webkit_source_.setExtraData(source_); |
| 210 webkit_source_id_ = webkit_source_.id(); |
| 211 |
| 212 InSequence s; |
| 213 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)); |
| 214 blink::WebMediaStreamTrack track = StartSource( |
| 215 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0); |
| 216 base::RunLoop().RunUntilIdle(); |
| 217 |
| 218 OnStarted(true); |
| 219 base::RunLoop().RunUntilIdle(); |
| 220 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateLive, |
| 221 webkit_source_.getReadyState()); |
| 222 |
| 223 EXPECT_FALSE(source_stopped_); |
| 224 |
| 225 EXPECT_CALL(mock_delegate(), StopCapture()); |
| 226 OnStarted(false); |
| 227 base::RunLoop().RunUntilIdle(); |
| 228 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, |
| 229 webkit_source_.getReadyState()); |
| 230 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. |
| 231 EXPECT_TRUE(source_stopped_); |
| 232 } |
| 233 |
| 234 TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbing) { |
| 235 std::unique_ptr<MockVideoCapturerSource> delegate( |
| 236 new MockVideoCapturerSource()); |
| 237 delegate_ = delegate.get(); |
| 238 EXPECT_CALL(*delegate_, GetPreferredFormats()); |
| 239 source_ = new MediaStreamVideoCapturerSource( |
| 240 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, |
| 241 base::Unretained(this)), |
| 242 std::move(delegate)); |
| 243 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), |
| 244 blink::WebMediaStreamSource::TypeVideo, |
| 245 blink::WebString::fromASCII("dummy_source_name"), |
| 246 false /* remote */); |
| 247 webkit_source_.setExtraData(source_); |
| 248 webkit_source_id_ = webkit_source_.id(); |
| 249 |
| 250 VideoCaptureDeliverFrameCB deliver_frame_cb; |
| 251 media::VideoCapturerSource::RunningCallback running_cb; |
| 252 |
| 253 InSequence s; |
| 254 // EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
| 255 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) |
| 256 .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb), |
| 257 testing::SaveArg<2>(&running_cb))); |
| 258 EXPECT_CALL(mock_delegate(), RequestRefreshFrame()); |
| 259 EXPECT_CALL(mock_delegate(), StopCapture()); |
| 260 blink::WebMediaStreamTrack track = StartSource( |
| 261 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0); |
| 262 running_cb.Run(true); |
| 263 |
| 264 base::RunLoop run_loop; |
| 265 base::TimeTicks reference_capture_time = |
| 266 base::TimeTicks::FromInternalValue(60013); |
| 267 base::TimeTicks capture_time; |
| 268 media::VideoFrameMetadata metadata; |
| 269 FakeMediaStreamVideoSink fake_sink( |
| 270 &capture_time, &metadata, |
| 271 media::BindToCurrentLoop(run_loop.QuitClosure())); |
| 272 fake_sink.ConnectToTrack(track); |
| 273 const scoped_refptr<media::VideoFrame> frame = |
| 274 media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2)); |
| 275 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 30.0); |
| 276 child_process_->io_task_runner()->PostTask( |
| 277 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); |
| 278 run_loop.Run(); |
| 279 fake_sink.DisconnectFromTrack(); |
| 280 EXPECT_EQ(reference_capture_time, capture_time); |
| 281 double metadata_value; |
| 282 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 283 &metadata_value)); |
| 284 EXPECT_EQ(30.0, metadata_value); |
| 285 } |
| 286 |
| 287 class MediaStreamVideoCapturerSourceOldConstraintsTest : public testing::Test { |
| 288 public: |
| 289 MediaStreamVideoCapturerSourceOldConstraintsTest() |
| 290 : child_process_(new ChildProcess()), |
| 291 source_(nullptr), |
| 292 delegate_(nullptr), |
| 293 source_stopped_(false) { |
| 294 scoped_feature_list_.InitAndEnableFeature( |
| 295 features::kMediaStreamOldVideoConstraints); |
| 296 } |
| 297 |
| 298 void TearDown() override { |
| 299 webkit_source_.reset(); |
| 300 blink::WebHeap::collectAllGarbageForTesting(); |
| 301 } |
| 302 |
| 303 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { |
| 304 std::unique_ptr<MockVideoCapturerSource> delegate( |
| 305 new MockVideoCapturerSource()); |
| 306 delegate_ = delegate.get(); |
| 307 source_ = new MediaStreamVideoCapturerSource( |
| 308 base::Bind( |
| 309 &MediaStreamVideoCapturerSourceOldConstraintsTest::OnSourceStopped, |
| 310 base::Unretained(this)), |
| 311 std::move(delegate)); |
| 312 source_->SetDeviceInfo(device_info); |
| 313 |
| 314 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), |
| 315 blink::WebMediaStreamSource::TypeVideo, |
| 316 blink::WebString::fromASCII("dummy_source_name"), |
| 317 false /* remote */); |
| 318 webkit_source_.setExtraData(source_); |
| 319 webkit_source_id_ = webkit_source_.id(); |
| 320 } |
| 321 |
| 322 MockConstraintFactory* constraint_factory() { return &constraint_factory_; } |
| 323 |
| 324 blink::WebMediaStreamTrack StartSource() { |
| 325 bool enabled = true; |
| 326 // CreateVideoTrack will trigger OnConstraintsApplied. |
| 327 return MediaStreamVideoTrack::CreateVideoTrack( |
| 328 source_, constraint_factory_.CreateWebMediaConstraints(), |
| 329 base::Bind(&MediaStreamVideoCapturerSourceOldConstraintsTest:: |
| 330 OnConstraintsApplied, |
| 331 base::Unretained(this)), |
| 332 enabled); |
| 333 } |
| 334 |
| 335 blink::WebMediaStreamTrack StartSource( |
| 336 const VideoTrackAdapterSettings& adapter_settings, |
| 337 const base::Optional<bool>& noise_reduction, |
| 338 bool is_screencast, |
| 339 double min_frame_rate) { |
| 340 bool enabled = true; |
| 341 // CreateVideoTrack will trigger OnConstraintsApplied. |
| 342 return MediaStreamVideoTrack::CreateVideoTrack( |
| 343 source_, adapter_settings, noise_reduction, is_screencast, |
| 344 min_frame_rate, |
| 345 base::Bind(&MediaStreamVideoCapturerSourceOldConstraintsTest:: |
| 346 OnConstraintsApplied, |
| 347 base::Unretained(this)), |
| 348 enabled); |
| 349 } |
| 350 |
| 351 MockVideoCapturerSource& mock_delegate() { return *delegate_; } |
| 352 |
| 353 const char* GetPowerLineFrequencyForTesting() const { |
| 354 return source_->GetPowerLineFrequencyForTesting(); |
| 355 } |
| 356 |
| 357 void OnSourceStopped(const blink::WebMediaStreamSource& source) { |
| 358 source_stopped_ = true; |
| 359 EXPECT_EQ(source.id(), webkit_source_id_); |
| 360 } |
| 361 void OnStarted(bool result) { source_->OnRunStateChanged(result); } |
| 362 |
| 363 protected: |
| 364 void OnConstraintsApplied(MediaStreamSource* source, |
| 365 MediaStreamRequestResult result, |
| 366 const blink::WebString& result_name) {} |
| 367 |
| 368 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
| 369 // and Sources below into believing they are on the right threads. |
| 370 base::MessageLoopForUI message_loop_; |
| 371 std::unique_ptr<ChildProcess> child_process_; |
| 372 |
| 373 blink::WebMediaStreamSource webkit_source_; |
| 374 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. |
| 375 MockVideoCapturerSource* delegate_; // owned by |source|. |
| 376 blink::WebString webkit_source_id_; |
| 377 bool source_stopped_; |
| 378 MockConstraintFactory constraint_factory_; |
| 379 base::test::ScopedFeatureList scoped_feature_list_; |
| 380 }; |
| 381 |
| 382 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, |
| 383 TabCaptureFixedResolutionByDefault) { |
162 StreamDeviceInfo device_info; | 384 StreamDeviceInfo device_info; |
163 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 385 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
164 InitWithDeviceInfo(device_info); | 386 InitWithDeviceInfo(device_info); |
165 | 387 |
166 // No constraints are being provided to the implementation, so expect only | 388 // No constraints are being provided to the implementation, so expect only |
167 // default values. | 389 // default values. |
168 media::VideoCaptureParams expected_params; | 390 media::VideoCaptureParams expected_params; |
169 expected_params.requested_format.frame_size.SetSize( | 391 expected_params.requested_format.frame_size.SetSize( |
170 MediaStreamVideoSource::kDefaultWidth, | 392 MediaStreamVideoSource::kDefaultWidth, |
171 MediaStreamVideoSource::kDefaultHeight); | 393 MediaStreamVideoSource::kDefaultHeight); |
172 expected_params.requested_format.frame_rate = | 394 expected_params.requested_format.frame_rate = |
173 MediaStreamVideoSource::kDefaultFrameRate; | 395 MediaStreamVideoSource::kDefaultFrameRate; |
174 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 396 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
175 expected_params.resolution_change_policy = | 397 expected_params.resolution_change_policy = |
176 media::RESOLUTION_POLICY_FIXED_RESOLUTION; | 398 media::RESOLUTION_POLICY_FIXED_RESOLUTION; |
177 | 399 |
178 InSequence s; | 400 InSequence s; |
179 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 401 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
180 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | 402 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); |
181 blink::WebMediaStreamTrack track = StartSource(); | 403 blink::WebMediaStreamTrack track = StartSource(); |
182 // When the track goes out of scope, the source will be stopped. | 404 // When the track goes out of scope, the source will be stopped. |
183 EXPECT_CALL(mock_delegate(), StopCapture()); | 405 EXPECT_CALL(mock_delegate(), StopCapture()); |
184 } | 406 } |
185 | 407 |
186 // This test does not apply with spec-compliant constraints. | 408 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, |
187 // TODO(guidou): Remove this test. http://crbug.com/706408 | 409 DesktopCaptureAllowAnyResolutionChangeByDefault) { |
188 TEST_F(MediaStreamVideoCapturerSourceTest, | |
189 DesktopCaptureAllowAnyResolutionChangeByDefaultOldConstraints) { | |
190 base::test::ScopedFeatureList scoped_feature_list; | |
191 scoped_feature_list.InitAndEnableFeature( | |
192 features::kMediaStreamOldVideoConstraints); | |
193 StreamDeviceInfo device_info; | 410 StreamDeviceInfo device_info; |
194 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | 411 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; |
195 InitWithDeviceInfo(device_info); | 412 InitWithDeviceInfo(device_info); |
196 | 413 |
197 // No constraints are being provided to the implementation, so expect only | 414 // No constraints are being provided to the implementation, so expect only |
198 // default values. | 415 // default values. |
199 media::VideoCaptureParams expected_params; | 416 media::VideoCaptureParams expected_params; |
200 expected_params.requested_format.frame_size.SetSize( | 417 expected_params.requested_format.frame_size.SetSize( |
201 MediaStreamVideoSource::kDefaultWidth, | 418 MediaStreamVideoSource::kDefaultWidth, |
202 MediaStreamVideoSource::kDefaultHeight); | 419 MediaStreamVideoSource::kDefaultHeight); |
203 expected_params.requested_format.frame_rate = | 420 expected_params.requested_format.frame_rate = |
204 MediaStreamVideoSource::kDefaultFrameRate; | 421 MediaStreamVideoSource::kDefaultFrameRate; |
205 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 422 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
206 expected_params.resolution_change_policy = | 423 expected_params.resolution_change_policy = |
207 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; | 424 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; |
208 | 425 |
209 InSequence s; | 426 InSequence s; |
210 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 427 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
211 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | 428 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); |
212 blink::WebMediaStreamTrack track = StartSource(); | 429 blink::WebMediaStreamTrack track = StartSource(); |
213 // When the track goes out of scope, the source will be stopped. | 430 // When the track goes out of scope, the source will be stopped. |
214 EXPECT_CALL(mock_delegate(), StopCapture()); | 431 EXPECT_CALL(mock_delegate(), StopCapture()); |
215 } | 432 } |
216 | 433 |
217 // This test does not apply with spec-compliant constraints. | 434 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, |
218 // TODO(guidou): Remove this test. http://crbug.com/706408 | 435 TabCaptureConstraintsImplyFixedAspectRatio) { |
219 TEST_F(MediaStreamVideoCapturerSourceTest, | |
220 TabCaptureConstraintsImplyFixedAspectRatioOldConstraints) { | |
221 base::test::ScopedFeatureList scoped_feature_list; | |
222 scoped_feature_list.InitAndEnableFeature( | |
223 features::kMediaStreamOldVideoConstraints); | |
224 StreamDeviceInfo device_info; | 436 StreamDeviceInfo device_info; |
225 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 437 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
226 InitWithDeviceInfo(device_info); | 438 InitWithDeviceInfo(device_info); |
227 | 439 |
228 // Specify max and min size constraints that have the same ~16:9 aspect ratio. | 440 // Specify max and min size constraints that have the same ~16:9 aspect ratio. |
229 constraint_factory()->basic().width.setMax(1920); | 441 constraint_factory()->basic().width.setMax(1920); |
230 constraint_factory()->basic().height.setMax(1080); | 442 constraint_factory()->basic().height.setMax(1080); |
231 constraint_factory()->basic().width.setMin(854); | 443 constraint_factory()->basic().width.setMin(854); |
232 constraint_factory()->basic().height.setMin(480); | 444 constraint_factory()->basic().height.setMin(480); |
233 constraint_factory()->basic().frameRate.setMax(60.0); | 445 constraint_factory()->basic().frameRate.setMax(60.0); |
(...skipping 11 matching lines...) Expand all Loading... |
245 mock_delegate(), | 457 mock_delegate(), |
246 StartCapture( | 458 StartCapture( |
247 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | 459 testing::Field(&media::VideoCaptureParams::resolution_change_policy, |
248 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), | 460 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), |
249 _, _)); | 461 _, _)); |
250 blink::WebMediaStreamTrack track = StartSource(); | 462 blink::WebMediaStreamTrack track = StartSource(); |
251 // When the track goes out of scope, the source will be stopped. | 463 // When the track goes out of scope, the source will be stopped. |
252 EXPECT_CALL(mock_delegate(), StopCapture()); | 464 EXPECT_CALL(mock_delegate(), StopCapture()); |
253 } | 465 } |
254 | 466 |
255 // This test does not apply with spec-compliant constraints. | 467 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, |
256 // TODO(guidou): Remove this test. http://crbug.com/706408 | 468 TabCaptureConstraintsImplyAllowingAnyResolutionChange) { |
257 TEST_F(MediaStreamVideoCapturerSourceTest, | |
258 TabCaptureConstraintsImplyAllowingAnyResolutionChangeOldConstraints) { | |
259 base::test::ScopedFeatureList scoped_feature_list; | |
260 scoped_feature_list.InitAndEnableFeature( | |
261 features::kMediaStreamOldVideoConstraints); | |
262 StreamDeviceInfo device_info; | 469 StreamDeviceInfo device_info; |
263 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 470 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
264 InitWithDeviceInfo(device_info); | 471 InitWithDeviceInfo(device_info); |
265 | 472 |
266 // Specify max and min size constraints with different aspect ratios. | 473 // Specify max and min size constraints with different aspect ratios. |
267 constraint_factory()->basic().width.setMax(1920); | 474 constraint_factory()->basic().width.setMax(1920); |
268 constraint_factory()->basic().height.setMax(1080); | 475 constraint_factory()->basic().height.setMax(1080); |
269 constraint_factory()->basic().width.setMin(0); | 476 constraint_factory()->basic().width.setMin(0); |
270 constraint_factory()->basic().height.setMin(0); | 477 constraint_factory()->basic().height.setMin(0); |
271 constraint_factory()->basic().frameRate.setMax(60.0); | 478 constraint_factory()->basic().frameRate.setMax(60.0); |
(...skipping 11 matching lines...) Expand all Loading... |
283 mock_delegate(), | 490 mock_delegate(), |
284 StartCapture( | 491 StartCapture( |
285 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | 492 testing::Field(&media::VideoCaptureParams::resolution_change_policy, |
286 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT), | 493 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT), |
287 _, _)); | 494 _, _)); |
288 blink::WebMediaStreamTrack track = StartSource(); | 495 blink::WebMediaStreamTrack track = StartSource(); |
289 // When the track goes out of scope, the source will be stopped. | 496 // When the track goes out of scope, the source will be stopped. |
290 EXPECT_CALL(mock_delegate(), StopCapture()); | 497 EXPECT_CALL(mock_delegate(), StopCapture()); |
291 } | 498 } |
292 | 499 |
293 // This test does not apply with spec-compliant constraints. | 500 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, |
294 // TODO(guidou): Remove this test. http://crbug.com/706408 | 501 DeviceCaptureConstraintsSupportPowerLineFrequency) { |
295 TEST_F(MediaStreamVideoCapturerSourceTest, | |
296 DeviceCaptureConstraintsSupportPowerLineFrequencyOldConstraints) { | |
297 base::test::ScopedFeatureList scoped_feature_list; | |
298 scoped_feature_list.InitAndEnableFeature( | |
299 features::kMediaStreamOldVideoConstraints); | |
300 for (int frequency = -100; frequency < 100; ++frequency) { | 502 for (int frequency = -100; frequency < 100; ++frequency) { |
301 StreamDeviceInfo device_info; | 503 StreamDeviceInfo device_info; |
302 device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; | 504 device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; |
303 InitWithDeviceInfo(device_info); | 505 InitWithDeviceInfo(device_info); |
304 constraint_factory_.Reset(); | 506 constraint_factory_.Reset(); |
305 | 507 |
306 constraint_factory()->AddAdvanced().googPowerLineFrequency.setExact( | 508 constraint_factory()->AddAdvanced().googPowerLineFrequency.setExact( |
307 frequency); | 509 frequency); |
308 | 510 |
309 media::VideoCaptureParams expected_params; | 511 media::VideoCaptureParams expected_params; |
(...skipping 18 matching lines...) Expand all Loading... |
328 | 530 |
329 InSequence s; | 531 InSequence s; |
330 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 532 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
331 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | 533 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); |
332 blink::WebMediaStreamTrack track = StartSource(); | 534 blink::WebMediaStreamTrack track = StartSource(); |
333 // When the track goes out of scope, the source will be stopped. | 535 // When the track goes out of scope, the source will be stopped. |
334 EXPECT_CALL(mock_delegate(), StopCapture()); | 536 EXPECT_CALL(mock_delegate(), StopCapture()); |
335 } | 537 } |
336 } | 538 } |
337 | 539 |
338 // TODO(guidou): Remove this test. http://crbug.com/706408 | 540 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, Ended) { |
339 TEST_F(MediaStreamVideoCapturerSourceTest, EndedOldConstraints) { | |
340 base::test::ScopedFeatureList scoped_feature_list; | |
341 scoped_feature_list.InitAndEnableFeature( | |
342 features::kMediaStreamOldVideoConstraints); | |
343 std::unique_ptr<MockVideoCapturerSource> delegate( | 541 std::unique_ptr<MockVideoCapturerSource> delegate( |
344 new MockVideoCapturerSource()); | 542 new MockVideoCapturerSource()); |
345 delegate_ = delegate.get(); | 543 delegate_ = delegate.get(); |
346 source_ = new MediaStreamVideoCapturerSource( | 544 source_ = new MediaStreamVideoCapturerSource( |
347 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | 545 base::Bind( |
348 base::Unretained(this)), | 546 &MediaStreamVideoCapturerSourceOldConstraintsTest::OnSourceStopped, |
| 547 base::Unretained(this)), |
349 std::move(delegate)); | 548 std::move(delegate)); |
350 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), | 549 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), |
351 blink::WebMediaStreamSource::TypeVideo, | 550 blink::WebMediaStreamSource::TypeVideo, |
352 blink::WebString::fromASCII("dummy_source_name"), | 551 blink::WebString::fromASCII("dummy_source_name"), |
353 false /* remote */); | 552 false /* remote */); |
354 webkit_source_.setExtraData(source_); | 553 webkit_source_.setExtraData(source_); |
355 webkit_source_id_ = webkit_source_.id(); | 554 webkit_source_id_ = webkit_source_.id(); |
356 | 555 |
357 InSequence s; | 556 InSequence s; |
358 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 557 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
(...skipping 10 matching lines...) Expand all Loading... |
369 | 568 |
370 EXPECT_CALL(mock_delegate(), StopCapture()); | 569 EXPECT_CALL(mock_delegate(), StopCapture()); |
371 OnStarted(false); | 570 OnStarted(false); |
372 base::RunLoop().RunUntilIdle(); | 571 base::RunLoop().RunUntilIdle(); |
373 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, | 572 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, |
374 webkit_source_.getReadyState()); | 573 webkit_source_.getReadyState()); |
375 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. | 574 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. |
376 EXPECT_TRUE(source_stopped_); | 575 EXPECT_TRUE(source_stopped_); |
377 } | 576 } |
378 | 577 |
379 TEST_F(MediaStreamVideoCapturerSourceTest, StartAndStop) { | 578 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, |
380 base::test::ScopedFeatureList scoped_feature_list; | 579 CaptureTimeAndMetadataPlumbing) { |
381 scoped_feature_list.InitAndDisableFeature( | |
382 features::kMediaStreamOldVideoConstraints); | |
383 std::unique_ptr<MockVideoCapturerSource> delegate( | |
384 new MockVideoCapturerSource()); | |
385 delegate_ = delegate.get(); | |
386 EXPECT_CALL(*delegate_, GetPreferredFormats()); | |
387 source_ = new MediaStreamVideoCapturerSource( | |
388 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | |
389 base::Unretained(this)), | |
390 std::move(delegate)); | |
391 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), | |
392 blink::WebMediaStreamSource::TypeVideo, | |
393 blink::WebString::fromASCII("dummy_source_name"), | |
394 false /* remote */); | |
395 webkit_source_.setExtraData(source_); | |
396 webkit_source_id_ = webkit_source_.id(); | |
397 | |
398 InSequence s; | |
399 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)); | |
400 blink::WebMediaStreamTrack track = StartSource( | |
401 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0); | |
402 base::RunLoop().RunUntilIdle(); | |
403 | |
404 OnStarted(true); | |
405 base::RunLoop().RunUntilIdle(); | |
406 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateLive, | |
407 webkit_source_.getReadyState()); | |
408 | |
409 EXPECT_FALSE(source_stopped_); | |
410 | |
411 EXPECT_CALL(mock_delegate(), StopCapture()); | |
412 OnStarted(false); | |
413 base::RunLoop().RunUntilIdle(); | |
414 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, | |
415 webkit_source_.getReadyState()); | |
416 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. | |
417 EXPECT_TRUE(source_stopped_); | |
418 } | |
419 | |
420 class FakeMediaStreamVideoSink : public MediaStreamVideoSink { | |
421 public: | |
422 FakeMediaStreamVideoSink(base::TimeTicks* capture_time, | |
423 media::VideoFrameMetadata* metadata, | |
424 base::Closure got_frame_cb) | |
425 : capture_time_(capture_time), | |
426 metadata_(metadata), | |
427 got_frame_cb_(got_frame_cb) {} | |
428 | |
429 void ConnectToTrack(const blink::WebMediaStreamTrack& track) { | |
430 MediaStreamVideoSink::ConnectToTrack( | |
431 track, base::Bind(&FakeMediaStreamVideoSink::OnVideoFrame, | |
432 base::Unretained(this)), | |
433 true); | |
434 } | |
435 | |
436 void DisconnectFromTrack() { | |
437 MediaStreamVideoSink::DisconnectFromTrack(); | |
438 } | |
439 | |
440 void OnVideoFrame(const scoped_refptr<media::VideoFrame>& frame, | |
441 base::TimeTicks capture_time) { | |
442 *capture_time_ = capture_time; | |
443 metadata_->Clear(); | |
444 metadata_->MergeMetadataFrom(frame->metadata()); | |
445 base::ResetAndReturn(&got_frame_cb_).Run(); | |
446 } | |
447 | |
448 private: | |
449 base::TimeTicks* const capture_time_; | |
450 media::VideoFrameMetadata* const metadata_; | |
451 base::Closure got_frame_cb_; | |
452 }; | |
453 | |
454 TEST_F(MediaStreamVideoCapturerSourceTest, | |
455 CaptureTimeAndMetadataPlumbingOldConstraints) { | |
456 base::test::ScopedFeatureList scoped_feature_list; | |
457 scoped_feature_list.InitAndEnableFeature( | |
458 features::kMediaStreamOldVideoConstraints); | |
459 StreamDeviceInfo device_info; | 580 StreamDeviceInfo device_info; |
460 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | 581 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; |
461 InitWithDeviceInfo(device_info); | 582 InitWithDeviceInfo(device_info); |
462 | 583 |
463 VideoCaptureDeliverFrameCB deliver_frame_cb; | 584 VideoCaptureDeliverFrameCB deliver_frame_cb; |
464 media::VideoCapturerSource::RunningCallback running_cb; | 585 media::VideoCapturerSource::RunningCallback running_cb; |
465 | 586 |
466 InSequence s; | 587 InSequence s; |
467 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 588 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
468 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) | 589 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) |
(...skipping 20 matching lines...) Expand all Loading... |
489 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); | 610 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); |
490 run_loop.Run(); | 611 run_loop.Run(); |
491 fake_sink.DisconnectFromTrack(); | 612 fake_sink.DisconnectFromTrack(); |
492 EXPECT_EQ(reference_capture_time, capture_time); | 613 EXPECT_EQ(reference_capture_time, capture_time); |
493 double metadata_value; | 614 double metadata_value; |
494 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 615 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
495 &metadata_value)); | 616 &metadata_value)); |
496 EXPECT_EQ(30.0, metadata_value); | 617 EXPECT_EQ(30.0, metadata_value); |
497 } | 618 } |
498 | 619 |
499 TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbing) { | |
500 base::test::ScopedFeatureList scoped_feature_list; | |
501 scoped_feature_list.InitAndDisableFeature( | |
502 features::kMediaStreamOldVideoConstraints); | |
503 std::unique_ptr<MockVideoCapturerSource> delegate( | |
504 new MockVideoCapturerSource()); | |
505 delegate_ = delegate.get(); | |
506 EXPECT_CALL(*delegate_, GetPreferredFormats()); | |
507 source_ = new MediaStreamVideoCapturerSource( | |
508 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | |
509 base::Unretained(this)), | |
510 std::move(delegate)); | |
511 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), | |
512 blink::WebMediaStreamSource::TypeVideo, | |
513 blink::WebString::fromASCII("dummy_source_name"), | |
514 false /* remote */); | |
515 webkit_source_.setExtraData(source_); | |
516 webkit_source_id_ = webkit_source_.id(); | |
517 | |
518 VideoCaptureDeliverFrameCB deliver_frame_cb; | |
519 media::VideoCapturerSource::RunningCallback running_cb; | |
520 | |
521 InSequence s; | |
522 // EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
523 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) | |
524 .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb), | |
525 testing::SaveArg<2>(&running_cb))); | |
526 EXPECT_CALL(mock_delegate(), RequestRefreshFrame()); | |
527 EXPECT_CALL(mock_delegate(), StopCapture()); | |
528 blink::WebMediaStreamTrack track = StartSource( | |
529 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0); | |
530 running_cb.Run(true); | |
531 | |
532 base::RunLoop run_loop; | |
533 base::TimeTicks reference_capture_time = | |
534 base::TimeTicks::FromInternalValue(60013); | |
535 base::TimeTicks capture_time; | |
536 media::VideoFrameMetadata metadata; | |
537 FakeMediaStreamVideoSink fake_sink( | |
538 &capture_time, &metadata, | |
539 media::BindToCurrentLoop(run_loop.QuitClosure())); | |
540 fake_sink.ConnectToTrack(track); | |
541 const scoped_refptr<media::VideoFrame> frame = | |
542 media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2)); | |
543 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 30.0); | |
544 child_process_->io_task_runner()->PostTask( | |
545 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); | |
546 run_loop.Run(); | |
547 fake_sink.DisconnectFromTrack(); | |
548 EXPECT_EQ(reference_capture_time, capture_time); | |
549 double metadata_value; | |
550 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, | |
551 &metadata_value)); | |
552 EXPECT_EQ(30.0, metadata_value); | |
553 } | |
554 | |
555 } // namespace content | 620 } // namespace content |
OLD | NEW |