| 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/audio_input_device_manager.h" | 5 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "content/public/common/media_stream_request.h" | 21 #include "content/public/common/media_stream_request.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "media/audio/audio_manager_base.h" | |
| 24 #include "media/audio/audio_system_impl.h" | 23 #include "media/audio/audio_system_impl.h" |
| 25 #include "media/audio/audio_thread_impl.h" | 24 #include "media/audio/audio_thread_impl.h" |
| 25 #include "media/audio/mock_audio_manager.h" |
| 26 #include "media/base/media_switches.h" | 26 #include "media/base/media_switches.h" |
| 27 #include "media/base/test_helpers.h" | 27 #include "media/base/test_helpers.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using testing::InSequence; | 31 using testing::InSequence; |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 class MockAudioInputDeviceManagerListener | 35 class MockAudioInputDeviceManagerListener |
| (...skipping 21 matching lines...) Expand all Loading... |
| 57 #define MAYBE_AudioInputDeviceManagerTest DISABLED_AudioInputDeviceManagerTest | 57 #define MAYBE_AudioInputDeviceManagerTest DISABLED_AudioInputDeviceManagerTest |
| 58 #else | 58 #else |
| 59 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest | 59 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 class MAYBE_AudioInputDeviceManagerTest : public testing::Test { | 62 class MAYBE_AudioInputDeviceManagerTest : public testing::Test { |
| 63 public: | 63 public: |
| 64 MAYBE_AudioInputDeviceManagerTest() {} | 64 MAYBE_AudioInputDeviceManagerTest() {} |
| 65 | 65 |
| 66 protected: | 66 protected: |
| 67 void SetUp() override { | 67 virtual void Initialize() { |
| 68 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 68 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 69 switches::kUseFakeDeviceForMediaStream); | 69 switches::kUseFakeDeviceForMediaStream); |
| 70 // AudioInputDeviceManager accesses AudioSystem from IO thread, so it never | 70 // AudioInputDeviceManager accesses AudioSystem from IO thread, so it never |
| 71 // runs on the same thread with it, even on Mac. | 71 // runs on the same thread with it, even on Mac. |
| 72 audio_manager_ = media::AudioManager::CreateForTesting( | 72 audio_manager_ = media::AudioManager::CreateForTesting( |
| 73 base::MakeUnique<media::AudioThreadImpl>()); | 73 base::MakeUnique<media::AudioThreadImpl>()); |
| 74 // Flush the message loop to ensure proper initialization of AudioManager. | 74 // Flush the message loop to ensure proper initialization of AudioManager. |
| 75 base::RunLoop().RunUntilIdle(); | 75 base::RunLoop().RunUntilIdle(); |
| 76 | 76 |
| 77 // Use fake devices. |
| 78 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", |
| 79 "fake_device_1"); |
| 80 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", |
| 81 "fake_device_2"); |
| 82 } |
| 83 |
| 84 void SetUp() override { |
| 85 Initialize(); |
| 86 |
| 77 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 87 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
| 78 manager_ = new AudioInputDeviceManager(audio_system_.get()); | 88 manager_ = new AudioInputDeviceManager(audio_system_.get()); |
| 79 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); | 89 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); |
| 80 manager_->RegisterListener(audio_input_listener_.get()); | 90 manager_->RegisterListener(audio_input_listener_.get()); |
| 81 | 91 |
| 82 // Use fake devices. | |
| 83 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", | |
| 84 "fake_device_1"); | |
| 85 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", | |
| 86 "fake_device_2"); | |
| 87 | |
| 88 // Wait until we get the list. | 92 // Wait until we get the list. |
| 89 base::RunLoop().RunUntilIdle(); | 93 base::RunLoop().RunUntilIdle(); |
| 90 } | 94 } |
| 91 | 95 |
| 92 void TearDown() override { | 96 void TearDown() override { |
| 93 manager_->UnregisterListener(audio_input_listener_.get()); | 97 manager_->UnregisterListener(audio_input_listener_.get()); |
| 94 audio_manager_->Shutdown(); | 98 audio_manager_->Shutdown(); |
| 95 } | 99 } |
| 96 | 100 |
| 97 void WaitForOpenCompletion() { | 101 void WaitForOpenCompletion() { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 manager_->GetOpenedDeviceInfoById(invalid_session_id); | 293 manager_->GetOpenedDeviceInfoById(invalid_session_id); |
| 290 DCHECK(!info); | 294 DCHECK(!info); |
| 291 | 295 |
| 292 manager_->Close(session_id); | 296 manager_->Close(session_id); |
| 293 EXPECT_CALL(*audio_input_listener_, | 297 EXPECT_CALL(*audio_input_listener_, |
| 294 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) | 298 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) |
| 295 .Times(1); | 299 .Times(1); |
| 296 base::RunLoop().RunUntilIdle(); | 300 base::RunLoop().RunUntilIdle(); |
| 297 } | 301 } |
| 298 | 302 |
| 303 class AudioInputDeviceManagerNoDevicesTest |
| 304 : public MAYBE_AudioInputDeviceManagerTest { |
| 305 public: |
| 306 AudioInputDeviceManagerNoDevicesTest(){}; |
| 307 |
| 308 protected: |
| 309 void Initialize() override { |
| 310 // MockAudioManager has no input and no output audio devices. |
| 311 audio_manager_ = base::MakeUnique<media::MockAudioManager>( |
| 312 base::MakeUnique<media::AudioThreadImpl>()); |
| 313 |
| 314 // Devices to request from AudioInputDeviceManager. |
| 315 devices_.emplace_back(MEDIA_TAB_AUDIO_CAPTURE, "Tab capture", |
| 316 "tab_capture"); |
| 317 devices_.emplace_back(MEDIA_DESKTOP_AUDIO_CAPTURE, "Desktop capture", |
| 318 "desktop_capture"); |
| 319 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device", |
| 320 "fake_device"); |
| 321 } |
| 322 |
| 323 private: |
| 324 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerNoDevicesTest); |
| 325 }; |
| 326 |
| 327 TEST_F(AudioInputDeviceManagerNoDevicesTest, |
| 328 ParametersValidWithoutAudioDevices) { |
| 329 ASSERT_FALSE(devices_.empty()); |
| 330 |
| 331 InSequence s; |
| 332 |
| 333 for (const auto& device_request : devices_) { |
| 334 int session_id = manager_->Open(device_request.device); |
| 335 |
| 336 EXPECT_CALL(*audio_input_listener_, |
| 337 Opened(device_request.device.type, session_id)) |
| 338 .Times(1); |
| 339 WaitForOpenCompletion(); |
| 340 |
| 341 // Expects that device parameters stored by the manager are valid. |
| 342 const StreamDeviceInfo* device_info = |
| 343 manager_->GetOpenedDeviceInfoById(session_id); |
| 344 EXPECT_TRUE( |
| 345 media::AudioParameters(media::AudioParameters::AUDIO_FAKE, |
| 346 static_cast<media::ChannelLayout>( |
| 347 device_info->device.input.channel_layout), |
| 348 device_info->device.input.sample_rate, 16, |
| 349 device_info->device.input.frames_per_buffer) |
| 350 .IsValid()); |
| 351 |
| 352 manager_->Close(session_id); |
| 353 EXPECT_CALL(*audio_input_listener_, |
| 354 Closed(device_request.device.type, session_id)) |
| 355 .Times(1); |
| 356 |
| 357 base::RunLoop().RunUntilIdle(); |
| 358 } |
| 359 } |
| 360 |
| 299 } // namespace content | 361 } // namespace content |
| OLD | NEW |