Chromium Code Reviews| 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 <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 | 57 |
| 58 const int kProcessId = 5; | 58 const int kProcessId = 5; |
| 59 const int kRenderId = 6; | 59 const int kRenderId = 6; |
| 60 const int kPageRequestId = 7; | 60 const int kPageRequestId = 7; |
| 61 | 61 |
| 62 namespace content { | 62 namespace content { |
| 63 | 63 |
| 64 namespace { | 64 namespace { |
| 65 | 65 |
| 66 void AudioInputDevicesEnumerated(base::Closure quit_closure, | 66 void AudioInputDevicesEnumerated(base::Closure quit_closure, |
| 67 media::AudioDeviceNames* out, | 67 media::AudioDeviceDescriptions* out, |
| 68 const MediaDeviceEnumeration& enumeration) { | 68 const MediaDeviceEnumeration& enumeration) { |
| 69 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { | 69 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { |
| 70 out->emplace_back(info.label, info.device_id); | 70 out->emplace_back(info.label, info.device_id, info.group_id); |
| 71 } | 71 } |
| 72 quit_closure.Run(); | 72 quit_closure.Run(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 77 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
| 78 public TestContentBrowserClient { | 78 public TestContentBrowserClient { |
| 79 public: | 79 public: |
| 80 MockMediaStreamDispatcherHost( | 80 MockMediaStreamDispatcherHost( |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 host_->OnOpenDevice(render_frame_id, page_request_id, device_id, | 340 host_->OnOpenDevice(render_frame_id, page_request_id, device_id, |
| 341 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, | 341 MEDIA_DEVICE_VIDEO_CAPTURE, origin_, |
| 342 run_loop.QuitClosure()); | 342 run_loop.QuitClosure()); |
| 343 run_loop.Run(); | 343 run_loop.Run(); |
| 344 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); | 344 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); |
| 345 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); | 345 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); |
| 346 } | 346 } |
| 347 | 347 |
| 348 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | 348 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
| 349 for (size_t i = 0; i < devices.size(); ++i) { | 349 for (size_t i = 0; i < devices.size(); ++i) { |
| 350 media::AudioDeviceNames::const_iterator audio_it = | 350 media::AudioDeviceDescriptions::const_iterator audio_it = |
| 351 physical_audio_devices_.begin(); | 351 physical_audio_devices_.begin(); |
| 352 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 352 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
|
Guido Urdaneta
2016/12/08 15:53:37
nit: consider switching to range for
o1ka
2016/12/09 14:56:30
Done.
| |
| 353 // Skip default and communications audio devices, whose IDs are not | 353 // Skip default and communications audio devices, whose IDs are not |
| 354 // translated. | 354 // translated. |
| 355 if (devices[i].device.id == | 355 if (devices[i].device.id == |
| 356 media::AudioDeviceDescription::kDefaultDeviceId || | 356 media::AudioDeviceDescription::kDefaultDeviceId || |
| 357 devices[i].device.id == | 357 devices[i].device.id == |
| 358 media::AudioDeviceDescription::kCommunicationsDeviceId) { | 358 media::AudioDeviceDescription::kCommunicationsDeviceId) { |
| 359 continue; | 359 continue; |
| 360 } | 360 } |
| 361 if (audio_it->unique_id == devices[i].device.id) | 361 if (audio_it->unique_id == devices[i].device.id) |
| 362 return true; | 362 return true; |
| 363 } | 363 } |
| 364 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 364 media::VideoCaptureDeviceDescriptors::const_iterator video_it = |
| 365 physical_video_devices_.begin(); | 365 physical_video_devices_.begin(); |
| 366 for (; video_it != physical_video_devices_.end(); ++video_it) { | 366 for (; video_it != physical_video_devices_.end(); ++video_it) { |
|
Guido Urdaneta
2016/12/08 15:53:37
nit: If you switch the above loop to range for, sw
o1ka
2016/12/09 14:56:30
Done.
| |
| 367 if (video_it->device_id == devices[i].device.id) | 367 if (video_it->device_id == devices[i].device.id) |
| 368 return true; | 368 return true; |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 return false; | 371 return false; |
| 372 } | 372 } |
| 373 | 373 |
| 374 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | 374 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
| 375 const url::Origin& origin) { | 375 const url::Origin& origin) { |
| 376 for (size_t i = 0; i < devices.size(); ++i) { | 376 for (size_t i = 0; i < devices.size(); ++i) { |
| 377 bool found_match = false; | 377 bool found_match = false; |
| 378 media::AudioDeviceNames::const_iterator audio_it = | 378 media::AudioDeviceDescriptions::const_iterator audio_it = |
| 379 physical_audio_devices_.begin(); | 379 physical_audio_devices_.begin(); |
| 380 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 380 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 381 if (content::DoesMediaDeviceIDMatchHMAC( | 381 if (content::DoesMediaDeviceIDMatchHMAC( |
| 382 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 382 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 383 origin, | 383 origin, |
| 384 devices[i].device.id, | 384 devices[i].device.id, |
| 385 audio_it->unique_id)) { | 385 audio_it->unique_id)) { |
| 386 EXPECT_FALSE(found_match); | 386 EXPECT_FALSE(found_match); |
| 387 found_match = true; | 387 found_match = true; |
| 388 } | 388 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 | 423 |
| 424 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 424 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
| 425 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 425 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 426 content::TestBrowserThreadBundle thread_bundle_; | 426 content::TestBrowserThreadBundle thread_bundle_; |
| 427 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> | 427 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> |
| 428 audio_manager_; | 428 audio_manager_; |
| 429 MockMediaStreamUIProxy* stream_ui_; | 429 MockMediaStreamUIProxy* stream_ui_; |
| 430 ContentBrowserClient* old_browser_client_; | 430 ContentBrowserClient* old_browser_client_; |
| 431 std::unique_ptr<ContentClient> content_client_; | 431 std::unique_ptr<ContentClient> content_client_; |
| 432 content::TestBrowserContext browser_context_; | 432 content::TestBrowserContext browser_context_; |
| 433 media::AudioDeviceNames physical_audio_devices_; | 433 media::AudioDeviceDescriptions physical_audio_devices_; |
| 434 media::VideoCaptureDeviceDescriptors physical_video_devices_; | 434 media::VideoCaptureDeviceDescriptors physical_video_devices_; |
| 435 url::Origin origin_; | 435 url::Origin origin_; |
| 436 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; | 436 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; |
| 437 }; | 437 }; |
| 438 | 438 |
| 439 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { | 439 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
| 440 StreamControls controls(false, true); | 440 StreamControls controls(false, true); |
| 441 | 441 |
| 442 SetupFakeUI(true); | 442 SetupFakeUI(true); |
| 443 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 443 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 run_loop1.Run(); | 593 run_loop1.Run(); |
| 594 run_loop2.Run(); | 594 run_loop2.Run(); |
| 595 } | 595 } |
| 596 | 596 |
| 597 // Test that we can generate streams where a sourceId is specified in | 597 // Test that we can generate streams where a sourceId is specified in |
| 598 // the request. | 598 // the request. |
| 599 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { | 599 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { |
| 600 ASSERT_GE(physical_audio_devices_.size(), 1u); | 600 ASSERT_GE(physical_audio_devices_.size(), 1u); |
| 601 ASSERT_GE(physical_video_devices_.size(), 1u); | 601 ASSERT_GE(physical_video_devices_.size(), 1u); |
| 602 | 602 |
| 603 media::AudioDeviceNames::const_iterator audio_it = | 603 media::AudioDeviceDescriptions::const_iterator audio_it = |
| 604 physical_audio_devices_.begin(); | 604 physical_audio_devices_.begin(); |
| 605 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 605 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 606 std::string source_id = content::GetHMACForMediaDeviceID( | 606 std::string source_id = content::GetHMACForMediaDeviceID( |
| 607 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 607 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), |
| 608 origin_, | 608 origin_, |
| 609 audio_it->unique_id); | 609 audio_it->unique_id); |
| 610 ASSERT_FALSE(source_id.empty()); | 610 ASSERT_FALSE(source_id.empty()); |
| 611 StreamControls controls(true, true); | 611 StreamControls controls(true, true); |
| 612 controls.audio.device_id = source_id; | 612 controls.audio.device_id = source_id; |
| 613 | 613 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 base::RunLoop run_loop; | 814 base::RunLoop run_loop; |
| 815 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 815 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
| 816 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 816 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 817 media_stream_manager_->media_devices_manager()->OnDevicesChanged( | 817 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
| 818 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 818 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
| 819 | 819 |
| 820 run_loop.Run(); | 820 run_loop.Run(); |
| 821 } | 821 } |
| 822 | 822 |
| 823 }; // namespace content | 823 }; // namespace content |
| OLD | NEW |