Chromium Code Reviews| 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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/test/scoped_feature_list.h" | |
| 16 #include "base/test/scoped_task_environment.h" | 15 #include "base/test/scoped_task_environment.h" |
| 17 #include "content/child/child_process.h" | 16 #include "content/child/child_process.h" |
| 18 #include "content/public/common/content_features.h" | |
| 19 #include "content/public/renderer/media_stream_video_sink.h" | 17 #include "content/public/renderer/media_stream_video_sink.h" |
| 20 #include "content/renderer/media/media_stream_video_track.h" | 18 #include "content/renderer/media/media_stream_video_track.h" |
| 21 #include "content/renderer/media/mock_constraint_factory.h" | |
| 22 #include "content/renderer/media/video_track_adapter.h" | 19 #include "content/renderer/media/video_track_adapter.h" |
| 23 #include "media/base/bind_to_current_loop.h" | 20 #include "media/base/bind_to_current_loop.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/WebKit/public/web/WebHeap.h" | 23 #include "third_party/WebKit/public/web/WebHeap.h" |
| 27 | 24 |
| 28 using ::testing::_; | 25 using ::testing::_; |
| 29 using ::testing::InSequence; | 26 using ::testing::InSequence; |
| 30 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 31 using ::testing::WithArgs; | 28 using ::testing::WithArgs; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 } // namespace | 100 } // namespace |
| 104 | 101 |
| 105 class MediaStreamVideoCapturerSourceTest : public testing::Test { | 102 class MediaStreamVideoCapturerSourceTest : public testing::Test { |
| 106 public: | 103 public: |
| 107 MediaStreamVideoCapturerSourceTest() | 104 MediaStreamVideoCapturerSourceTest() |
| 108 : scoped_task_environment_( | 105 : scoped_task_environment_( |
| 109 base::test::ScopedTaskEnvironment::MainThreadType::UI), | 106 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 110 child_process_(new ChildProcess()), | 107 child_process_(new ChildProcess()), |
| 111 source_(nullptr), | 108 source_(nullptr), |
| 112 delegate_(nullptr), | 109 delegate_(nullptr), |
| 113 source_stopped_(false) { | 110 source_stopped_(false) {} |
| 114 scoped_feature_list_.InitAndDisableFeature( | |
| 115 features::kMediaStreamOldVideoConstraints); | |
| 116 } | |
| 117 | 111 |
| 118 void TearDown() override { | 112 void TearDown() override { |
| 119 webkit_source_.Reset(); | 113 webkit_source_.Reset(); |
| 120 blink::WebHeap::CollectAllGarbageForTesting(); | 114 blink::WebHeap::CollectAllGarbageForTesting(); |
| 121 } | 115 } |
| 122 | 116 |
| 123 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { | 117 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { |
| 124 std::unique_ptr<MockVideoCapturerSource> delegate( | 118 std::unique_ptr<MockVideoCapturerSource> delegate( |
| 125 new MockVideoCapturerSource()); | 119 new MockVideoCapturerSource()); |
| 126 delegate_ = delegate.get(); | 120 delegate_ = delegate.get(); |
| 127 source_ = new MediaStreamVideoCapturerSource( | 121 source_ = new MediaStreamVideoCapturerSource( |
| 128 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | 122 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, |
| 129 base::Unretained(this)), | 123 base::Unretained(this)), |
| 130 std::move(delegate)); | 124 std::move(delegate)); |
| 131 source_->SetDeviceInfo(device_info); | 125 source_->SetDeviceInfo(device_info); |
| 132 | 126 |
| 133 webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), | 127 webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), |
| 134 blink::WebMediaStreamSource::kTypeVideo, | 128 blink::WebMediaStreamSource::kTypeVideo, |
| 135 blink::WebString::FromASCII("dummy_source_name"), | 129 blink::WebString::FromASCII("dummy_source_name"), |
| 136 false /* remote */); | 130 false /* remote */); |
| 137 webkit_source_.SetExtraData(source_); | 131 webkit_source_.SetExtraData(source_); |
| 138 webkit_source_id_ = webkit_source_.Id(); | 132 webkit_source_id_ = webkit_source_.Id(); |
| 139 } | 133 } |
| 140 | 134 |
| 141 MockConstraintFactory* constraint_factory() { return &constraint_factory_; } | |
| 142 | |
| 143 blink::WebMediaStreamTrack StartSource() { | |
| 144 bool enabled = true; | |
| 145 // CreateVideoTrack will trigger OnConstraintsApplied. | |
| 146 return MediaStreamVideoTrack::CreateVideoTrack( | |
| 147 source_, constraint_factory_.CreateWebMediaConstraints(), | |
| 148 base::Bind(&MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, | |
| 149 base::Unretained(this)), | |
| 150 enabled); | |
| 151 } | |
| 152 | |
| 153 blink::WebMediaStreamTrack StartSource( | 135 blink::WebMediaStreamTrack StartSource( |
| 154 const VideoTrackAdapterSettings& adapter_settings, | 136 const VideoTrackAdapterSettings& adapter_settings, |
| 155 const base::Optional<bool>& noise_reduction, | 137 const base::Optional<bool>& noise_reduction, |
| 156 bool is_screencast, | 138 bool is_screencast, |
| 157 double min_frame_rate) { | 139 double min_frame_rate) { |
| 158 bool enabled = true; | 140 bool enabled = true; |
| 159 // CreateVideoTrack will trigger OnConstraintsApplied. | 141 // CreateVideoTrack will trigger OnConstraintsApplied. |
| 160 return MediaStreamVideoTrack::CreateVideoTrack( | 142 return MediaStreamVideoTrack::CreateVideoTrack( |
| 161 source_, adapter_settings, noise_reduction, is_screencast, | 143 source_, adapter_settings, noise_reduction, is_screencast, |
| 162 min_frame_rate, | 144 min_frame_rate, |
| 163 base::Bind(&MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, | 145 base::Bind(&MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, |
| 164 base::Unretained(this)), | 146 base::Unretained(this)), |
| 165 enabled); | 147 enabled); |
| 166 } | 148 } |
| 167 | 149 |
| 168 MockVideoCapturerSource& mock_delegate() { return *delegate_; } | 150 MockVideoCapturerSource& mock_delegate() { return *delegate_; } |
| 169 | 151 |
| 170 const char* GetPowerLineFrequencyForTesting() const { | 152 const char* GetPowerLineFrequencyForTesting() const { |
| 171 return source_->GetPowerLineFrequencyForTesting(); | 153 return source_->GetPowerLineFrequencyForTesting(); |
| 172 } | 154 } |
|
hbos_chromium
2017/06/30 15:04:12
Power line: remove this?
Guido Urdaneta
2017/07/03 18:43:16
Done.
| |
| 173 | 155 |
| 174 void OnSourceStopped(const blink::WebMediaStreamSource& source) { | 156 void OnSourceStopped(const blink::WebMediaStreamSource& source) { |
| 175 source_stopped_ = true; | 157 source_stopped_ = true; |
| 176 EXPECT_EQ(source.Id(), webkit_source_id_); | 158 EXPECT_EQ(source.Id(), webkit_source_id_); |
| 177 } | 159 } |
| 178 void OnStarted(bool result) { source_->OnRunStateChanged(result); } | 160 void OnStarted(bool result) { source_->OnRunStateChanged(result); } |
| 179 | 161 |
| 180 protected: | 162 protected: |
| 181 void OnConstraintsApplied(MediaStreamSource* source, | 163 void OnConstraintsApplied(MediaStreamSource* source, |
| 182 MediaStreamRequestResult result, | 164 MediaStreamRequestResult result, |
| 183 const blink::WebString& result_name) {} | 165 const blink::WebString& result_name) {} |
| 184 | 166 |
| 185 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 167 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
| 186 // and Sources below into believing they are on the right threads. | 168 // and Sources below into believing they are on the right threads. |
| 187 base::test::ScopedTaskEnvironment scoped_task_environment_; | 169 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 188 std::unique_ptr<ChildProcess> child_process_; | 170 std::unique_ptr<ChildProcess> child_process_; |
| 189 | 171 |
| 190 blink::WebMediaStreamSource webkit_source_; | 172 blink::WebMediaStreamSource webkit_source_; |
| 191 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. | 173 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. |
| 192 MockVideoCapturerSource* delegate_; // owned by |source|. | 174 MockVideoCapturerSource* delegate_; // owned by |source|. |
| 193 blink::WebString webkit_source_id_; | 175 blink::WebString webkit_source_id_; |
| 194 bool source_stopped_; | 176 bool source_stopped_; |
| 195 MockConstraintFactory constraint_factory_; | |
| 196 base::test::ScopedFeatureList scoped_feature_list_; | |
| 197 }; | 177 }; |
| 198 | 178 |
| 199 TEST_F(MediaStreamVideoCapturerSourceTest, StartAndStop) { | 179 TEST_F(MediaStreamVideoCapturerSourceTest, StartAndStop) { |
| 200 std::unique_ptr<MockVideoCapturerSource> delegate( | 180 std::unique_ptr<MockVideoCapturerSource> delegate( |
| 201 new MockVideoCapturerSource()); | 181 new MockVideoCapturerSource()); |
| 202 delegate_ = delegate.get(); | 182 delegate_ = delegate.get(); |
| 203 EXPECT_CALL(*delegate_, GetPreferredFormats()); | 183 EXPECT_CALL(*delegate_, GetPreferredFormats()); |
| 204 source_ = new MediaStreamVideoCapturerSource( | 184 source_ = new MediaStreamVideoCapturerSource( |
| 205 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | 185 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, |
| 206 base::Unretained(this)), | 186 base::Unretained(this)), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); | 260 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); |
| 281 run_loop.Run(); | 261 run_loop.Run(); |
| 282 fake_sink.DisconnectFromTrack(); | 262 fake_sink.DisconnectFromTrack(); |
| 283 EXPECT_EQ(reference_capture_time, capture_time); | 263 EXPECT_EQ(reference_capture_time, capture_time); |
| 284 double metadata_value; | 264 double metadata_value; |
| 285 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 265 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 286 &metadata_value)); | 266 &metadata_value)); |
| 287 EXPECT_EQ(30.0, metadata_value); | 267 EXPECT_EQ(30.0, metadata_value); |
| 288 } | 268 } |
| 289 | 269 |
| 290 class MediaStreamVideoCapturerSourceOldConstraintsTest : public testing::Test { | |
| 291 public: | |
| 292 MediaStreamVideoCapturerSourceOldConstraintsTest() | |
| 293 : scoped_task_environment_( | |
| 294 base::test::ScopedTaskEnvironment::MainThreadType::UI), | |
| 295 child_process_(new ChildProcess()), | |
| 296 source_(nullptr), | |
| 297 delegate_(nullptr), | |
| 298 source_stopped_(false) { | |
| 299 scoped_feature_list_.InitAndEnableFeature( | |
| 300 features::kMediaStreamOldVideoConstraints); | |
| 301 } | |
| 302 | |
| 303 void TearDown() override { | |
| 304 webkit_source_.Reset(); | |
| 305 blink::WebHeap::CollectAllGarbageForTesting(); | |
| 306 } | |
| 307 | |
| 308 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { | |
| 309 std::unique_ptr<MockVideoCapturerSource> delegate( | |
| 310 new MockVideoCapturerSource()); | |
| 311 delegate_ = delegate.get(); | |
| 312 source_ = new MediaStreamVideoCapturerSource( | |
| 313 base::Bind( | |
| 314 &MediaStreamVideoCapturerSourceOldConstraintsTest::OnSourceStopped, | |
| 315 base::Unretained(this)), | |
| 316 std::move(delegate)); | |
| 317 source_->SetDeviceInfo(device_info); | |
| 318 | |
| 319 webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), | |
| 320 blink::WebMediaStreamSource::kTypeVideo, | |
| 321 blink::WebString::FromASCII("dummy_source_name"), | |
| 322 false /* remote */); | |
| 323 webkit_source_.SetExtraData(source_); | |
| 324 webkit_source_id_ = webkit_source_.Id(); | |
| 325 } | |
| 326 | |
| 327 MockConstraintFactory* constraint_factory() { return &constraint_factory_; } | |
| 328 | |
| 329 blink::WebMediaStreamTrack StartSource() { | |
| 330 bool enabled = true; | |
| 331 // CreateVideoTrack will trigger OnConstraintsApplied. | |
| 332 return MediaStreamVideoTrack::CreateVideoTrack( | |
| 333 source_, constraint_factory_.CreateWebMediaConstraints(), | |
| 334 base::Bind(&MediaStreamVideoCapturerSourceOldConstraintsTest:: | |
| 335 OnConstraintsApplied, | |
| 336 base::Unretained(this)), | |
| 337 enabled); | |
| 338 } | |
| 339 | |
| 340 blink::WebMediaStreamTrack StartSource( | |
| 341 const VideoTrackAdapterSettings& adapter_settings, | |
| 342 const base::Optional<bool>& noise_reduction, | |
| 343 bool is_screencast, | |
| 344 double min_frame_rate) { | |
| 345 bool enabled = true; | |
| 346 // CreateVideoTrack will trigger OnConstraintsApplied. | |
| 347 return MediaStreamVideoTrack::CreateVideoTrack( | |
| 348 source_, adapter_settings, noise_reduction, is_screencast, | |
| 349 min_frame_rate, | |
| 350 base::Bind(&MediaStreamVideoCapturerSourceOldConstraintsTest:: | |
| 351 OnConstraintsApplied, | |
| 352 base::Unretained(this)), | |
| 353 enabled); | |
| 354 } | |
| 355 | |
| 356 MockVideoCapturerSource& mock_delegate() { return *delegate_; } | |
| 357 | |
| 358 const char* GetPowerLineFrequencyForTesting() const { | |
| 359 return source_->GetPowerLineFrequencyForTesting(); | |
| 360 } | |
| 361 | |
| 362 void OnSourceStopped(const blink::WebMediaStreamSource& source) { | |
| 363 source_stopped_ = true; | |
| 364 EXPECT_EQ(source.Id(), webkit_source_id_); | |
| 365 } | |
| 366 void OnStarted(bool result) { source_->OnRunStateChanged(result); } | |
| 367 | |
| 368 protected: | |
| 369 void OnConstraintsApplied(MediaStreamSource* source, | |
| 370 MediaStreamRequestResult result, | |
| 371 const blink::WebString& result_name) {} | |
| 372 | |
| 373 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | |
| 374 // and Sources below into believing they are on the right threads. | |
| 375 base::test::ScopedTaskEnvironment scoped_task_environment_; | |
| 376 std::unique_ptr<ChildProcess> child_process_; | |
| 377 | |
| 378 blink::WebMediaStreamSource webkit_source_; | |
| 379 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. | |
| 380 MockVideoCapturerSource* delegate_; // owned by |source|. | |
| 381 blink::WebString webkit_source_id_; | |
| 382 bool source_stopped_; | |
| 383 MockConstraintFactory constraint_factory_; | |
| 384 base::test::ScopedFeatureList scoped_feature_list_; | |
| 385 }; | |
| 386 | |
| 387 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, | |
| 388 TabCaptureFixedResolutionByDefault) { | |
| 389 StreamDeviceInfo device_info; | |
| 390 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | |
| 391 InitWithDeviceInfo(device_info); | |
| 392 | |
| 393 // No constraints are being provided to the implementation, so expect only | |
| 394 // default values. | |
| 395 media::VideoCaptureParams expected_params; | |
| 396 expected_params.requested_format.frame_size.SetSize( | |
| 397 MediaStreamVideoSource::kDefaultWidth, | |
| 398 MediaStreamVideoSource::kDefaultHeight); | |
| 399 expected_params.requested_format.frame_rate = | |
| 400 MediaStreamVideoSource::kDefaultFrameRate; | |
| 401 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | |
| 402 expected_params.resolution_change_policy = | |
| 403 media::RESOLUTION_POLICY_FIXED_RESOLUTION; | |
| 404 | |
| 405 InSequence s; | |
| 406 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
| 407 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | |
| 408 blink::WebMediaStreamTrack track = StartSource(); | |
| 409 // When the track goes out of scope, the source will be stopped. | |
| 410 EXPECT_CALL(mock_delegate(), StopCapture()); | |
| 411 } | |
| 412 | |
| 413 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, | |
| 414 DesktopCaptureAllowAnyResolutionChangeByDefault) { | |
| 415 StreamDeviceInfo device_info; | |
| 416 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | |
| 417 InitWithDeviceInfo(device_info); | |
| 418 | |
| 419 // No constraints are being provided to the implementation, so expect only | |
| 420 // default values. | |
| 421 media::VideoCaptureParams expected_params; | |
| 422 expected_params.requested_format.frame_size.SetSize( | |
| 423 MediaStreamVideoSource::kDefaultWidth, | |
| 424 MediaStreamVideoSource::kDefaultHeight); | |
| 425 expected_params.requested_format.frame_rate = | |
| 426 MediaStreamVideoSource::kDefaultFrameRate; | |
| 427 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | |
| 428 expected_params.resolution_change_policy = | |
| 429 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; | |
| 430 | |
| 431 InSequence s; | |
| 432 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
| 433 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | |
| 434 blink::WebMediaStreamTrack track = StartSource(); | |
| 435 // When the track goes out of scope, the source will be stopped. | |
| 436 EXPECT_CALL(mock_delegate(), StopCapture()); | |
| 437 } | |
| 438 | |
| 439 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, | |
| 440 TabCaptureConstraintsImplyFixedAspectRatio) { | |
| 441 StreamDeviceInfo device_info; | |
| 442 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | |
| 443 InitWithDeviceInfo(device_info); | |
| 444 | |
| 445 // Specify max and min size constraints that have the same ~16:9 aspect ratio. | |
| 446 constraint_factory()->basic().width.SetMax(1920); | |
| 447 constraint_factory()->basic().height.SetMax(1080); | |
| 448 constraint_factory()->basic().width.SetMin(854); | |
| 449 constraint_factory()->basic().height.SetMin(480); | |
| 450 constraint_factory()->basic().frame_rate.SetMax(60.0); | |
| 451 | |
| 452 media::VideoCaptureParams expected_params; | |
| 453 expected_params.requested_format.frame_size.SetSize(1920, 1080); | |
| 454 expected_params.requested_format.frame_rate = 60.0; | |
| 455 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | |
| 456 expected_params.resolution_change_policy = | |
| 457 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; | |
| 458 | |
| 459 InSequence s; | |
| 460 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
| 461 EXPECT_CALL( | |
| 462 mock_delegate(), | |
| 463 StartCapture( | |
| 464 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | |
| 465 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), | |
| 466 _, _)); | |
| 467 blink::WebMediaStreamTrack track = StartSource(); | |
| 468 // When the track goes out of scope, the source will be stopped. | |
| 469 EXPECT_CALL(mock_delegate(), StopCapture()); | |
| 470 } | |
| 471 | |
| 472 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, | |
| 473 TabCaptureConstraintsImplyAllowingAnyResolutionChange) { | |
| 474 StreamDeviceInfo device_info; | |
| 475 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | |
| 476 InitWithDeviceInfo(device_info); | |
| 477 | |
| 478 // Specify max and min size constraints with different aspect ratios. | |
| 479 constraint_factory()->basic().width.SetMax(1920); | |
| 480 constraint_factory()->basic().height.SetMax(1080); | |
| 481 constraint_factory()->basic().width.SetMin(0); | |
| 482 constraint_factory()->basic().height.SetMin(0); | |
| 483 constraint_factory()->basic().frame_rate.SetMax(60.0); | |
| 484 | |
| 485 media::VideoCaptureParams expected_params; | |
| 486 expected_params.requested_format.frame_size.SetSize(1920, 1080); | |
| 487 expected_params.requested_format.frame_rate = 60.0; | |
| 488 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | |
| 489 expected_params.resolution_change_policy = | |
| 490 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; | |
| 491 | |
| 492 InSequence s; | |
| 493 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
| 494 EXPECT_CALL( | |
| 495 mock_delegate(), | |
| 496 StartCapture( | |
| 497 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | |
| 498 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT), | |
| 499 _, _)); | |
| 500 blink::WebMediaStreamTrack track = StartSource(); | |
| 501 // When the track goes out of scope, the source will be stopped. | |
| 502 EXPECT_CALL(mock_delegate(), StopCapture()); | |
| 503 } | |
| 504 | |
| 505 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, | |
| 506 DeviceCaptureConstraintsSupportPowerLineFrequency) { | |
| 507 for (int frequency = -100; frequency < 100; ++frequency) { | |
| 508 StreamDeviceInfo device_info; | |
| 509 device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; | |
| 510 InitWithDeviceInfo(device_info); | |
| 511 constraint_factory_.Reset(); | |
| 512 | |
| 513 constraint_factory()->AddAdvanced().goog_power_line_frequency.SetExact( | |
| 514 frequency); | |
| 515 | |
| 516 media::VideoCaptureParams expected_params; | |
| 517 expected_params.requested_format.frame_size.SetSize( | |
| 518 MediaStreamVideoSource::kDefaultWidth, | |
| 519 MediaStreamVideoSource::kDefaultHeight); | |
| 520 expected_params.requested_format.frame_rate = | |
| 521 MediaStreamVideoSource::kDefaultFrameRate; | |
| 522 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | |
| 523 expected_params.resolution_change_policy = | |
| 524 media::RESOLUTION_POLICY_FIXED_RESOLUTION; | |
| 525 if (frequency == 50) { | |
| 526 expected_params.power_line_frequency = | |
| 527 media::PowerLineFrequency::FREQUENCY_50HZ; | |
| 528 } else if (frequency == 60) { | |
| 529 expected_params.power_line_frequency = | |
| 530 media::PowerLineFrequency::FREQUENCY_60HZ; | |
| 531 } else { | |
| 532 expected_params.power_line_frequency = | |
| 533 media::PowerLineFrequency::FREQUENCY_DEFAULT; | |
| 534 } | |
| 535 | |
| 536 InSequence s; | |
| 537 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
| 538 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | |
| 539 blink::WebMediaStreamTrack track = StartSource(); | |
| 540 // When the track goes out of scope, the source will be stopped. | |
| 541 EXPECT_CALL(mock_delegate(), StopCapture()); | |
| 542 } | |
| 543 } | |
| 544 | |
| 545 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, Ended) { | |
| 546 std::unique_ptr<MockVideoCapturerSource> delegate( | |
| 547 new MockVideoCapturerSource()); | |
| 548 delegate_ = delegate.get(); | |
| 549 source_ = new MediaStreamVideoCapturerSource( | |
| 550 base::Bind( | |
| 551 &MediaStreamVideoCapturerSourceOldConstraintsTest::OnSourceStopped, | |
| 552 base::Unretained(this)), | |
| 553 std::move(delegate)); | |
| 554 webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), | |
| 555 blink::WebMediaStreamSource::kTypeVideo, | |
| 556 blink::WebString::FromASCII("dummy_source_name"), | |
| 557 false /* remote */); | |
| 558 webkit_source_.SetExtraData(source_); | |
| 559 webkit_source_id_ = webkit_source_.Id(); | |
| 560 | |
| 561 InSequence s; | |
| 562 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
| 563 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)); | |
| 564 blink::WebMediaStreamTrack track = StartSource(); | |
| 565 base::RunLoop().RunUntilIdle(); | |
| 566 | |
| 567 OnStarted(true); | |
| 568 base::RunLoop().RunUntilIdle(); | |
| 569 EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateLive, | |
| 570 webkit_source_.GetReadyState()); | |
| 571 | |
| 572 EXPECT_FALSE(source_stopped_); | |
| 573 | |
| 574 EXPECT_CALL(mock_delegate(), StopCapture()); | |
| 575 OnStarted(false); | |
| 576 base::RunLoop().RunUntilIdle(); | |
| 577 EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded, | |
| 578 webkit_source_.GetReadyState()); | |
| 579 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. | |
| 580 EXPECT_TRUE(source_stopped_); | |
| 581 } | |
| 582 | |
| 583 TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, | |
| 584 CaptureTimeAndMetadataPlumbing) { | |
| 585 StreamDeviceInfo device_info; | |
| 586 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | |
| 587 InitWithDeviceInfo(device_info); | |
| 588 | |
| 589 VideoCaptureDeliverFrameCB deliver_frame_cb; | |
| 590 media::VideoCapturerSource::RunningCallback running_cb; | |
| 591 | |
| 592 InSequence s; | |
| 593 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
| 594 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) | |
| 595 .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb), | |
| 596 testing::SaveArg<2>(&running_cb))); | |
| 597 EXPECT_CALL(mock_delegate(), RequestRefreshFrame()); | |
| 598 EXPECT_CALL(mock_delegate(), StopCapture()); | |
| 599 blink::WebMediaStreamTrack track = StartSource(); | |
| 600 running_cb.Run(true); | |
| 601 | |
| 602 base::RunLoop run_loop; | |
| 603 base::TimeTicks reference_capture_time = | |
| 604 base::TimeTicks::FromInternalValue(60013); | |
| 605 base::TimeTicks capture_time; | |
| 606 media::VideoFrameMetadata metadata; | |
| 607 FakeMediaStreamVideoSink fake_sink( | |
| 608 &capture_time, &metadata, | |
| 609 media::BindToCurrentLoop(run_loop.QuitClosure())); | |
| 610 fake_sink.ConnectToTrack(track); | |
| 611 const scoped_refptr<media::VideoFrame> frame = | |
| 612 media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2)); | |
| 613 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 30.0); | |
| 614 child_process_->io_task_runner()->PostTask( | |
| 615 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); | |
| 616 run_loop.Run(); | |
| 617 fake_sink.DisconnectFromTrack(); | |
| 618 EXPECT_EQ(reference_capture_time, capture_time); | |
| 619 double metadata_value; | |
| 620 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, | |
| 621 &metadata_value)); | |
| 622 EXPECT_EQ(30.0, metadata_value); | |
| 623 } | |
| 624 | |
| 625 } // namespace content | 270 } // namespace content |
| OLD | NEW |