OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/audio/audio_manager.h" | 5 #include "media/audio/audio_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "chromeos/dbus/fake_cras_audio_client.h" | 46 #include "chromeos/dbus/fake_cras_audio_client.h" |
47 #include "media/audio/cras/audio_manager_cras.h" | 47 #include "media/audio/cras/audio_manager_cras.h" |
48 #endif // defined(USE_CRAS) | 48 #endif // defined(USE_CRAS) |
49 | 49 |
50 namespace media { | 50 namespace media { |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 template <typename T> | 54 template <typename T> |
55 struct TestAudioManagerFactory { | 55 struct TestAudioManagerFactory { |
56 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { | 56 static std::unique_ptr<AudioManager> Create( |
57 return ScopedAudioManagerPtr(new T(base::ThreadTaskRunnerHandle::Get(), | 57 AudioLogFactory* audio_log_factory) { |
58 base::ThreadTaskRunnerHandle::Get(), | 58 return base::MakeUnique<T>(base::ThreadTaskRunnerHandle::Get(), |
59 audio_log_factory)); | 59 base::ThreadTaskRunnerHandle::Get(), |
| 60 audio_log_factory); |
60 } | 61 } |
61 }; | 62 }; |
62 | 63 |
63 #if defined(USE_PULSEAUDIO) | 64 #if defined(USE_PULSEAUDIO) |
64 template <> | 65 template <> |
65 struct TestAudioManagerFactory<AudioManagerPulse> { | 66 struct TestAudioManagerFactory<AudioManagerPulse> { |
66 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { | 67 static std::unique_ptr<AudioManager> Create( |
67 std::unique_ptr<AudioManagerPulse, AudioManagerDeleter> manager( | 68 AudioLogFactory* audio_log_factory) { |
68 new AudioManagerPulse(base::ThreadTaskRunnerHandle::Get(), | 69 auto manager = base::MakeUnique<AudioManagerPulse>( |
69 base::ThreadTaskRunnerHandle::Get(), | 70 base::ThreadTaskRunnerHandle::Get(), |
70 audio_log_factory)); | 71 base::ThreadTaskRunnerHandle::Get(), audio_log_factory); |
71 if (!manager->Init()) | 72 if (!manager->Init()) |
72 manager.reset(); | 73 manager.reset(); |
73 return std::move(manager); | 74 return manager; |
74 } | 75 } |
75 }; | 76 }; |
76 #endif // defined(USE_PULSEAUDIO) | 77 #endif // defined(USE_PULSEAUDIO) |
77 | 78 |
78 template <> | 79 template <> |
79 struct TestAudioManagerFactory<std::nullptr_t> { | 80 struct TestAudioManagerFactory<std::nullptr_t> { |
80 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { | 81 static std::unique_ptr<AudioManager> Create( |
| 82 AudioLogFactory* audio_log_factory) { |
81 return AudioManager::CreateForTesting(base::ThreadTaskRunnerHandle::Get()); | 83 return AudioManager::CreateForTesting(base::ThreadTaskRunnerHandle::Get()); |
82 } | 84 } |
83 }; | 85 }; |
84 | 86 |
85 #if defined(USE_CRAS) | 87 #if defined(USE_CRAS) |
86 using chromeos::AudioNode; | 88 using chromeos::AudioNode; |
87 using chromeos::AudioNodeList; | 89 using chromeos::AudioNodeList; |
88 | 90 |
89 const uint64_t kJabraSpeaker1Id = 30001; | 91 const uint64_t kJabraSpeaker1Id = 30001; |
90 const uint64_t kJabraSpeaker1StableDeviceId = 80001; | 92 const uint64_t kJabraSpeaker1StableDeviceId = 80001; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 audio_client_->SetAudioNodesForTesting(audio_nodes); | 228 audio_client_->SetAudioNodesForTesting(audio_nodes); |
227 audio_pref_handler_ = new chromeos::AudioDevicesPrefHandlerStub(); | 229 audio_pref_handler_ = new chromeos::AudioDevicesPrefHandlerStub(); |
228 chromeos::CrasAudioHandler::Initialize(audio_pref_handler_); | 230 chromeos::CrasAudioHandler::Initialize(audio_pref_handler_); |
229 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); | 231 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); |
230 base::RunLoop().RunUntilIdle(); | 232 base::RunLoop().RunUntilIdle(); |
231 } | 233 } |
232 #endif // defined(USE_CRAS) | 234 #endif // defined(USE_CRAS) |
233 | 235 |
234 protected: | 236 protected: |
235 AudioManagerTest() { CreateAudioManagerForTesting(); } | 237 AudioManagerTest() { CreateAudioManagerForTesting(); } |
236 ~AudioManagerTest() override {} | 238 ~AudioManagerTest() override { audio_manager_->Shutdown(); } |
237 | 239 |
238 // Helper method which verifies that the device list starts with a valid | 240 // Helper method which verifies that the device list starts with a valid |
239 // default record followed by non-default device names. | 241 // default record followed by non-default device names. |
240 static void CheckDeviceDescriptions( | 242 static void CheckDeviceDescriptions( |
241 const AudioDeviceDescriptions& device_descriptions) { | 243 const AudioDeviceDescriptions& device_descriptions) { |
242 DVLOG(2) << "Got " << device_descriptions.size() << " audio devices."; | 244 DVLOG(2) << "Got " << device_descriptions.size() << " audio devices."; |
243 if (!device_descriptions.empty()) { | 245 if (!device_descriptions.empty()) { |
244 AudioDeviceDescriptions::const_iterator it = device_descriptions.begin(); | 246 AudioDeviceDescriptions::const_iterator it = device_descriptions.begin(); |
245 | 247 |
246 // The first device in the list should always be the default device. | 248 // The first device in the list should always be the default device. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 TestAudioManagerFactory<T>::Create(&fake_audio_log_factory_); | 339 TestAudioManagerFactory<T>::Create(&fake_audio_log_factory_); |
338 // A few AudioManager implementations post initialization tasks to | 340 // A few AudioManager implementations post initialization tasks to |
339 // audio thread. Flush the thread to ensure that |audio_manager_| is | 341 // audio thread. Flush the thread to ensure that |audio_manager_| is |
340 // initialized and ready to use before returning from this function. | 342 // initialized and ready to use before returning from this function. |
341 // TODO(alokp): We should perhaps do this in AudioManager::Create(). | 343 // TODO(alokp): We should perhaps do this in AudioManager::Create(). |
342 base::RunLoop().RunUntilIdle(); | 344 base::RunLoop().RunUntilIdle(); |
343 } | 345 } |
344 | 346 |
345 base::TestMessageLoop message_loop_; | 347 base::TestMessageLoop message_loop_; |
346 FakeAudioLogFactory fake_audio_log_factory_; | 348 FakeAudioLogFactory fake_audio_log_factory_; |
347 ScopedAudioManagerPtr audio_manager_; | 349 std::unique_ptr<AudioManager> audio_manager_; |
348 | 350 |
349 #if defined(USE_CRAS) | 351 #if defined(USE_CRAS) |
350 chromeos::CrasAudioHandler* cras_audio_handler_ = nullptr; // Not owned. | 352 chromeos::CrasAudioHandler* cras_audio_handler_ = nullptr; // Not owned. |
351 chromeos::FakeCrasAudioClient* audio_client_ = nullptr; // Not owned. | 353 chromeos::FakeCrasAudioClient* audio_client_ = nullptr; // Not owned. |
352 scoped_refptr<chromeos::AudioDevicesPrefHandlerStub> audio_pref_handler_; | 354 scoped_refptr<chromeos::AudioDevicesPrefHandlerStub> audio_pref_handler_; |
353 #endif // defined(USE_CRAS) | 355 #endif // defined(USE_CRAS) |
354 }; | 356 }; |
355 | 357 |
356 #if defined(USE_CRAS) | 358 #if defined(USE_CRAS) |
357 // TODO(warx): enable the test once crbug.com/554168 is fixed. | 359 // TODO(warx): enable the test once crbug.com/554168 is fixed. |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 | 668 |
667 base::FilePath file_path(FILE_PATH_LITERAL("path")); | 669 base::FilePath file_path(FILE_PATH_LITERAL("path")); |
668 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); | 670 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); |
669 audio_manager_->EnableOutputDebugRecording(file_path); | 671 audio_manager_->EnableOutputDebugRecording(file_path); |
670 | 672 |
671 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); | 673 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
672 audio_manager_->DisableOutputDebugRecording(); | 674 audio_manager_->DisableOutputDebugRecording(); |
673 } | 675 } |
674 | 676 |
675 } // namespace media | 677 } // namespace media |
OLD | NEW |