| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/media/media_stream_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 #endif | 288 #endif |
| 289 } | 289 } |
| 290 | 290 |
| 291 ~MediaStreamDispatcherHostTest() override { | 291 ~MediaStreamDispatcherHostTest() override { |
| 292 #if defined(OS_CHROMEOS) | 292 #if defined(OS_CHROMEOS) |
| 293 chromeos::CrasAudioHandler::Shutdown(); | 293 chromeos::CrasAudioHandler::Shutdown(); |
| 294 #endif | 294 #endif |
| 295 } | 295 } |
| 296 | 296 |
| 297 void SetUp() override { | 297 void SetUp() override { |
| 298 video_capture_device_factory_->GetDeviceNames(&physical_video_devices_); | 298 video_capture_device_factory_->GetDeviceDescriptors( |
| 299 &physical_video_devices_); |
| 299 ASSERT_GT(physical_video_devices_.size(), 0u); | 300 ASSERT_GT(physical_video_devices_.size(), 0u); |
| 300 | 301 |
| 301 media_stream_manager_->audio_input_device_manager()->GetFakeDeviceNames( | 302 media_stream_manager_->audio_input_device_manager()->GetFakeDeviceNames( |
| 302 &physical_audio_devices_); | 303 &physical_audio_devices_); |
| 303 ASSERT_GT(physical_audio_devices_.size(), 0u); | 304 ASSERT_GT(physical_audio_devices_.size(), 0u); |
| 304 } | 305 } |
| 305 | 306 |
| 306 void TearDown() override { host_->OnChannelClosing(); } | 307 void TearDown() override { host_->OnChannelClosing(); } |
| 307 | 308 |
| 308 protected: | 309 protected: |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 391 } |
| 391 | 392 |
| 392 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | 393 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
| 393 for (size_t i = 0; i < devices.size(); ++i) { | 394 for (size_t i = 0; i < devices.size(); ++i) { |
| 394 media::AudioDeviceNames::const_iterator audio_it = | 395 media::AudioDeviceNames::const_iterator audio_it = |
| 395 physical_audio_devices_.begin(); | 396 physical_audio_devices_.begin(); |
| 396 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 397 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 397 if (audio_it->unique_id == devices[i].device.id) | 398 if (audio_it->unique_id == devices[i].device.id) |
| 398 return true; | 399 return true; |
| 399 } | 400 } |
| 400 media::VideoCaptureDevice::Names::const_iterator video_it = | 401 media::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 401 physical_video_devices_.begin(); | 402 physical_video_devices_.begin(); |
| 402 for (; video_it != physical_video_devices_.end(); ++video_it) { | 403 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 403 if (video_it->id() == devices[i].device.id) | 404 if (video_it->device_id == devices[i].device.id) |
| 404 return true; | 405 return true; |
| 405 } | 406 } |
| 406 } | 407 } |
| 407 return false; | 408 return false; |
| 408 } | 409 } |
| 409 | 410 |
| 410 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | 411 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
| 411 const url::Origin& origin) { | 412 const url::Origin& origin) { |
| 412 for (size_t i = 0; i < devices.size(); ++i) { | 413 for (size_t i = 0; i < devices.size(); ++i) { |
| 413 bool found_match = false; | 414 bool found_match = false; |
| 414 media::AudioDeviceNames::const_iterator audio_it = | 415 media::AudioDeviceNames::const_iterator audio_it = |
| 415 physical_audio_devices_.begin(); | 416 physical_audio_devices_.begin(); |
| 416 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 417 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 417 if (content::DoesMediaDeviceIDMatchHMAC( | 418 if (content::DoesMediaDeviceIDMatchHMAC( |
| 418 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 419 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 419 origin, | 420 origin, |
| 420 devices[i].device.id, | 421 devices[i].device.id, |
| 421 audio_it->unique_id)) { | 422 audio_it->unique_id)) { |
| 422 EXPECT_FALSE(found_match); | 423 EXPECT_FALSE(found_match); |
| 423 found_match = true; | 424 found_match = true; |
| 424 } | 425 } |
| 425 } | 426 } |
| 426 media::VideoCaptureDevice::Names::const_iterator video_it = | 427 media::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 427 physical_video_devices_.begin(); | 428 physical_video_devices_.begin(); |
| 428 for (; video_it != physical_video_devices_.end(); ++video_it) { | 429 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 429 if (content::DoesMediaDeviceIDMatchHMAC( | 430 if (content::DoesMediaDeviceIDMatchHMAC( |
| 430 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 431 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 431 origin, | 432 origin, devices[i].device.id, video_it->device_id)) { |
| 432 devices[i].device.id, | |
| 433 video_it->id())) { | |
| 434 EXPECT_FALSE(found_match); | 433 EXPECT_FALSE(found_match); |
| 435 found_match = true; | 434 found_match = true; |
| 436 } | 435 } |
| 437 } | 436 } |
| 438 if (!found_match) | 437 if (!found_match) |
| 439 return false; | 438 return false; |
| 440 } | 439 } |
| 441 return true; | 440 return true; |
| 442 } | 441 } |
| 443 | 442 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 462 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 461 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
| 463 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 462 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 464 content::TestBrowserThreadBundle thread_bundle_; | 463 content::TestBrowserThreadBundle thread_bundle_; |
| 465 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> | 464 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> |
| 466 audio_manager_; | 465 audio_manager_; |
| 467 MockMediaStreamUIProxy* stream_ui_; | 466 MockMediaStreamUIProxy* stream_ui_; |
| 468 ContentBrowserClient* old_browser_client_; | 467 ContentBrowserClient* old_browser_client_; |
| 469 std::unique_ptr<ContentClient> content_client_; | 468 std::unique_ptr<ContentClient> content_client_; |
| 470 content::TestBrowserContext browser_context_; | 469 content::TestBrowserContext browser_context_; |
| 471 media::AudioDeviceNames physical_audio_devices_; | 470 media::AudioDeviceNames physical_audio_devices_; |
| 472 media::VideoCaptureDevice::Names physical_video_devices_; | 471 media::VideoCaptureDeviceDescriptors physical_video_devices_; |
| 473 url::Origin origin_; | 472 url::Origin origin_; |
| 474 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; | 473 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; |
| 475 }; | 474 }; |
| 476 | 475 |
| 477 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { | 476 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
| 478 StreamControls controls(false, true); | 477 StreamControls controls(false, true); |
| 479 | 478 |
| 480 SetupFakeUI(true); | 479 SetupFakeUI(true); |
| 481 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 480 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 482 | 481 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 audio_it->unique_id); | 646 audio_it->unique_id); |
| 648 ASSERT_FALSE(source_id.empty()); | 647 ASSERT_FALSE(source_id.empty()); |
| 649 StreamControls controls(true, true); | 648 StreamControls controls(true, true); |
| 650 controls.audio.device_ids.push_back(source_id); | 649 controls.audio.device_ids.push_back(source_id); |
| 651 | 650 |
| 652 SetupFakeUI(true); | 651 SetupFakeUI(true); |
| 653 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 652 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 654 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); | 653 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); |
| 655 } | 654 } |
| 656 | 655 |
| 657 media::VideoCaptureDevice::Names::const_iterator video_it = | 656 media::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 658 physical_video_devices_.begin(); | 657 physical_video_devices_.begin(); |
| 659 for (; video_it != physical_video_devices_.end(); ++video_it) { | 658 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 660 std::string source_id = content::GetHMACForMediaDeviceID( | 659 std::string source_id = content::GetHMACForMediaDeviceID( |
| 661 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 660 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, |
| 662 origin_, | 661 video_it->device_id); |
| 663 video_it->id()); | |
| 664 ASSERT_FALSE(source_id.empty()); | 662 ASSERT_FALSE(source_id.empty()); |
| 665 StreamControls controls(true, true); | 663 StreamControls controls(true, true); |
| 666 controls.video.device_ids.push_back(source_id); | 664 controls.video.device_ids.push_back(source_id); |
| 667 | 665 |
| 668 SetupFakeUI(true); | 666 SetupFakeUI(true); |
| 669 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 667 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 670 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); | 668 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); |
| 671 } | 669 } |
| 672 } | 670 } |
| 673 | 671 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 686 audio_it->unique_id); | 684 audio_it->unique_id); |
| 687 ASSERT_FALSE(source_id.empty()); | 685 ASSERT_FALSE(source_id.empty()); |
| 688 StreamControls controls(true, true); | 686 StreamControls controls(true, true); |
| 689 controls.audio.device_ids.push_back(source_id); | 687 controls.audio.device_ids.push_back(source_id); |
| 690 | 688 |
| 691 SetupFakeUI(true); | 689 SetupFakeUI(true); |
| 692 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 690 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 693 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); | 691 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); |
| 694 } | 692 } |
| 695 | 693 |
| 696 media::VideoCaptureDevice::Names::const_iterator video_it = | 694 media::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 697 physical_video_devices_.begin(); | 695 physical_video_devices_.begin(); |
| 698 for (; video_it != physical_video_devices_.end(); ++video_it) { | 696 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 699 std::string source_id = content::GetHMACForMediaDeviceID( | 697 std::string source_id = content::GetHMACForMediaDeviceID( |
| 700 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 698 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, |
| 701 origin_, | 699 video_it->device_id); |
| 702 video_it->id()); | |
| 703 ASSERT_FALSE(source_id.empty()); | 700 ASSERT_FALSE(source_id.empty()); |
| 704 StreamControls controls(true, true); | 701 StreamControls controls(true, true); |
| 705 controls.video.device_ids.push_back(source_id); | 702 controls.video.device_ids.push_back(source_id); |
| 706 | 703 |
| 707 SetupFakeUI(true); | 704 SetupFakeUI(true); |
| 708 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 705 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 709 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); | 706 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); |
| 710 } | 707 } |
| 711 } | 708 } |
| 712 | 709 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 StreamControls controls(true, true); | 745 StreamControls controls(true, true); |
| 749 controls.video.alternate_device_ids.push_back("invalid source id"); | 746 controls.video.alternate_device_ids.push_back("invalid source id"); |
| 750 | 747 |
| 751 SetupFakeUI(true); | 748 SetupFakeUI(true); |
| 752 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 749 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 753 } | 750 } |
| 754 | 751 |
| 755 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { | 752 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { |
| 756 physical_video_devices_.clear(); | 753 physical_video_devices_.clear(); |
| 757 video_capture_device_factory_->set_number_of_devices(0); | 754 video_capture_device_factory_->set_number_of_devices(0); |
| 758 video_capture_device_factory_->GetDeviceNames(&physical_video_devices_); | 755 video_capture_device_factory_->GetDeviceDescriptors(&physical_video_devices_); |
| 759 StreamControls controls(true, true); | 756 StreamControls controls(true, true); |
| 760 | 757 |
| 761 SetupFakeUI(false); | 758 SetupFakeUI(false); |
| 762 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, | 759 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, |
| 763 MEDIA_DEVICE_NO_HARDWARE); | 760 MEDIA_DEVICE_NO_HARDWARE); |
| 764 } | 761 } |
| 765 | 762 |
| 766 // Test that if a OnStopStreamDevice message is received for a device that has | 763 // Test that if a OnStopStreamDevice message is received for a device that has |
| 767 // been opened in a MediaStream and by pepper, the device is only stopped for | 764 // been opened in a MediaStream and by pepper, the device is only stopped for |
| 768 // the MediaStream. | 765 // the MediaStream. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 | 951 |
| 955 TEST_F(MediaStreamDispatcherHostTest, DeviceChangeNotification) { | 952 TEST_F(MediaStreamDispatcherHostTest, DeviceChangeNotification) { |
| 956 SetupFakeUI(false); | 953 SetupFakeUI(false); |
| 957 // warm up the cache | 954 // warm up the cache |
| 958 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 955 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
| 959 MEDIA_DEVICE_VIDEO_CAPTURE); | 956 MEDIA_DEVICE_VIDEO_CAPTURE); |
| 960 SubscribeToDeviceChangeNotificationsAndWaitForNotification(kRenderId); | 957 SubscribeToDeviceChangeNotificationsAndWaitForNotification(kRenderId); |
| 961 } | 958 } |
| 962 | 959 |
| 963 }; // namespace content | 960 }; // namespace content |
| OLD | NEW |