| 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 14 matching lines...) Expand all Loading... |
| 25 #include "content/browser/renderer_host/media/video_capture_manager.h" | 25 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 26 #include "content/common/media/media_stream_messages.h" | 26 #include "content/common/media/media_stream_messages.h" |
| 27 #include "content/common/media/media_stream_options.h" | 27 #include "content/common/media/media_stream_options.h" |
| 28 #include "content/public/browser/media_device_id.h" | 28 #include "content/public/browser/media_device_id.h" |
| 29 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/test/mock_resource_context.h" | 30 #include "content/public/test/mock_resource_context.h" |
| 31 #include "content/public/test/test_browser_context.h" | 31 #include "content/public/test/test_browser_context.h" |
| 32 #include "content/public/test/test_browser_thread_bundle.h" | 32 #include "content/public/test/test_browser_thread_bundle.h" |
| 33 #include "content/test/test_content_browser_client.h" | 33 #include "content/test/test_content_browser_client.h" |
| 34 #include "content/test/test_content_client.h" | 34 #include "content/test/test_content_client.h" |
| 35 #include "device/capture/video/fake_video_capture_device_factory.h" |
| 35 #include "ipc/ipc_message_macros.h" | 36 #include "ipc/ipc_message_macros.h" |
| 36 #include "media/audio/mock_audio_manager.h" | 37 #include "media/audio/mock_audio_manager.h" |
| 37 #include "media/base/media_switches.h" | 38 #include "media/base/media_switches.h" |
| 38 #include "media/capture/video/fake_video_capture_device_factory.h" | |
| 39 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 43 #include "url/origin.h" | 43 #include "url/origin.h" |
| 44 | 44 |
| 45 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
| 46 #include "chromeos/audio/cras_audio_handler.h" | 46 #include "chromeos/audio/cras_audio_handler.h" |
| 47 #endif | 47 #endif |
| 48 | 48 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 old_browser_client_(NULL), | 253 old_browser_client_(NULL), |
| 254 origin_(GURL("https://test.com")) { | 254 origin_(GURL("https://test.com")) { |
| 255 audio_manager_.reset( | 255 audio_manager_.reset( |
| 256 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); | 256 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); |
| 257 // Make sure we use fake devices to avoid long delays. | 257 // Make sure we use fake devices to avoid long delays. |
| 258 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 258 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 259 switches::kUseFakeDeviceForMediaStream); | 259 switches::kUseFakeDeviceForMediaStream); |
| 260 // Create our own MediaStreamManager. | 260 // Create our own MediaStreamManager. |
| 261 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 261 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 262 video_capture_device_factory_ = | 262 video_capture_device_factory_ = |
| 263 static_cast<media::FakeVideoCaptureDeviceFactory*>( | 263 static_cast<device::FakeVideoCaptureDeviceFactory*>( |
| 264 media_stream_manager_->video_capture_manager() | 264 media_stream_manager_->video_capture_manager() |
| 265 ->video_capture_device_factory()); | 265 ->video_capture_device_factory()); |
| 266 DCHECK(video_capture_device_factory_); | 266 DCHECK(video_capture_device_factory_); |
| 267 #if defined(OS_WIN) | 267 #if defined(OS_WIN) |
| 268 // Override the Video Capture Thread that MediaStreamManager constructs. | 268 // Override the Video Capture Thread that MediaStreamManager constructs. |
| 269 media_stream_manager_->video_capture_manager()->set_device_task_runner( | 269 media_stream_manager_->video_capture_manager()->set_device_task_runner( |
| 270 base::ThreadTaskRunnerHandle::Get()); | 270 base::ThreadTaskRunnerHandle::Get()); |
| 271 #endif | 271 #endif |
| 272 | 272 |
| 273 MockResourceContext* mock_resource_context = | 273 MockResourceContext* mock_resource_context = |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } | 391 } |
| 392 | 392 |
| 393 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | 393 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
| 394 for (size_t i = 0; i < devices.size(); ++i) { | 394 for (size_t i = 0; i < devices.size(); ++i) { |
| 395 media::AudioDeviceNames::const_iterator audio_it = | 395 media::AudioDeviceNames::const_iterator audio_it = |
| 396 physical_audio_devices_.begin(); | 396 physical_audio_devices_.begin(); |
| 397 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 397 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 398 if (audio_it->unique_id == devices[i].device.id) | 398 if (audio_it->unique_id == devices[i].device.id) |
| 399 return true; | 399 return true; |
| 400 } | 400 } |
| 401 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 401 device::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 402 physical_video_devices_.begin(); | 402 physical_video_devices_.begin(); |
| 403 for (; video_it != physical_video_devices_.end(); ++video_it) { | 403 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 404 if (video_it->device_id == devices[i].device.id) | 404 if (video_it->device_id == devices[i].device.id) |
| 405 return true; | 405 return true; |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 return false; | 408 return false; |
| 409 } | 409 } |
| 410 | 410 |
| 411 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | 411 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
| 412 const url::Origin& origin) { | 412 const url::Origin& origin) { |
| 413 for (size_t i = 0; i < devices.size(); ++i) { | 413 for (size_t i = 0; i < devices.size(); ++i) { |
| 414 bool found_match = false; | 414 bool found_match = false; |
| 415 media::AudioDeviceNames::const_iterator audio_it = | 415 media::AudioDeviceNames::const_iterator audio_it = |
| 416 physical_audio_devices_.begin(); | 416 physical_audio_devices_.begin(); |
| 417 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 417 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 418 if (content::DoesMediaDeviceIDMatchHMAC( | 418 if (content::DoesMediaDeviceIDMatchHMAC( |
| 419 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 419 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 420 origin, | 420 origin, |
| 421 devices[i].device.id, | 421 devices[i].device.id, |
| 422 audio_it->unique_id)) { | 422 audio_it->unique_id)) { |
| 423 EXPECT_FALSE(found_match); | 423 EXPECT_FALSE(found_match); |
| 424 found_match = true; | 424 found_match = true; |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 427 device::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 428 physical_video_devices_.begin(); | 428 physical_video_devices_.begin(); |
| 429 for (; video_it != physical_video_devices_.end(); ++video_it) { | 429 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 430 if (content::DoesMediaDeviceIDMatchHMAC( | 430 if (content::DoesMediaDeviceIDMatchHMAC( |
| 431 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 431 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 432 origin, devices[i].device.id, video_it->device_id)) { | 432 origin, devices[i].device.id, video_it->device_id)) { |
| 433 EXPECT_FALSE(found_match); | 433 EXPECT_FALSE(found_match); |
| 434 found_match = true; | 434 found_match = true; |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 if (!found_match) | 437 if (!found_match) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 461 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 461 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
| 462 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 462 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 463 content::TestBrowserThreadBundle thread_bundle_; | 463 content::TestBrowserThreadBundle thread_bundle_; |
| 464 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> | 464 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> |
| 465 audio_manager_; | 465 audio_manager_; |
| 466 MockMediaStreamUIProxy* stream_ui_; | 466 MockMediaStreamUIProxy* stream_ui_; |
| 467 ContentBrowserClient* old_browser_client_; | 467 ContentBrowserClient* old_browser_client_; |
| 468 std::unique_ptr<ContentClient> content_client_; | 468 std::unique_ptr<ContentClient> content_client_; |
| 469 content::TestBrowserContext browser_context_; | 469 content::TestBrowserContext browser_context_; |
| 470 media::AudioDeviceNames physical_audio_devices_; | 470 media::AudioDeviceNames physical_audio_devices_; |
| 471 media::VideoCaptureDeviceDescriptors physical_video_devices_; | 471 device::VideoCaptureDeviceDescriptors physical_video_devices_; |
| 472 url::Origin origin_; | 472 url::Origin origin_; |
| 473 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; | 473 device::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; |
| 474 }; | 474 }; |
| 475 | 475 |
| 476 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { | 476 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
| 477 StreamControls controls(false, true); | 477 StreamControls controls(false, true); |
| 478 | 478 |
| 479 SetupFakeUI(true); | 479 SetupFakeUI(true); |
| 480 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 480 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 481 | 481 |
| 482 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 482 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 483 EXPECT_EQ(host_->video_devices_.size(), 1u); | 483 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 audio_it->unique_id); | 646 audio_it->unique_id); |
| 647 ASSERT_FALSE(source_id.empty()); | 647 ASSERT_FALSE(source_id.empty()); |
| 648 StreamControls controls(true, true); | 648 StreamControls controls(true, true); |
| 649 controls.audio.device_ids.push_back(source_id); | 649 controls.audio.device_ids.push_back(source_id); |
| 650 | 650 |
| 651 SetupFakeUI(true); | 651 SetupFakeUI(true); |
| 652 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 652 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 653 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); | 653 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); |
| 654 } | 654 } |
| 655 | 655 |
| 656 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 656 device::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 657 physical_video_devices_.begin(); | 657 physical_video_devices_.begin(); |
| 658 for (; video_it != physical_video_devices_.end(); ++video_it) { | 658 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 659 std::string source_id = content::GetHMACForMediaDeviceID( | 659 std::string source_id = content::GetHMACForMediaDeviceID( |
| 660 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, | 660 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, |
| 661 video_it->device_id); | 661 video_it->device_id); |
| 662 ASSERT_FALSE(source_id.empty()); | 662 ASSERT_FALSE(source_id.empty()); |
| 663 StreamControls controls(true, true); | 663 StreamControls controls(true, true); |
| 664 controls.video.device_ids.push_back(source_id); | 664 controls.video.device_ids.push_back(source_id); |
| 665 | 665 |
| 666 SetupFakeUI(true); | 666 SetupFakeUI(true); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 684 audio_it->unique_id); | 684 audio_it->unique_id); |
| 685 ASSERT_FALSE(source_id.empty()); | 685 ASSERT_FALSE(source_id.empty()); |
| 686 StreamControls controls(true, true); | 686 StreamControls controls(true, true); |
| 687 controls.audio.device_ids.push_back(source_id); | 687 controls.audio.device_ids.push_back(source_id); |
| 688 | 688 |
| 689 SetupFakeUI(true); | 689 SetupFakeUI(true); |
| 690 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 690 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| 691 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); | 691 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); |
| 692 } | 692 } |
| 693 | 693 |
| 694 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 694 device::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 695 physical_video_devices_.begin(); | 695 physical_video_devices_.begin(); |
| 696 for (; video_it != physical_video_devices_.end(); ++video_it) { | 696 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 697 std::string source_id = content::GetHMACForMediaDeviceID( | 697 std::string source_id = content::GetHMACForMediaDeviceID( |
| 698 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, | 698 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, |
| 699 video_it->device_id); | 699 video_it->device_id); |
| 700 ASSERT_FALSE(source_id.empty()); | 700 ASSERT_FALSE(source_id.empty()); |
| 701 StreamControls controls(true, true); | 701 StreamControls controls(true, true); |
| 702 controls.video.device_ids.push_back(source_id); | 702 controls.video.device_ids.push_back(source_id); |
| 703 | 703 |
| 704 SetupFakeUI(true); | 704 SetupFakeUI(true); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 | 951 |
| 952 TEST_F(MediaStreamDispatcherHostTest, DeviceChangeNotification) { | 952 TEST_F(MediaStreamDispatcherHostTest, DeviceChangeNotification) { |
| 953 SetupFakeUI(false); | 953 SetupFakeUI(false); |
| 954 // warm up the cache | 954 // warm up the cache |
| 955 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 955 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
| 956 MEDIA_DEVICE_VIDEO_CAPTURE); | 956 MEDIA_DEVICE_VIDEO_CAPTURE); |
| 957 SubscribeToDeviceChangeNotificationsAndWaitForNotification(kRenderId); | 957 SubscribeToDeviceChangeNotificationsAndWaitForNotification(kRenderId); |
| 958 } | 958 } |
| 959 | 959 |
| 960 }; // namespace content | 960 }; // namespace content |
| OLD | NEW |