| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/test/test_message_loop.h" | 14 #include "base/test/test_message_loop.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_device_description.h" |
| 18 #include "media/audio/audio_manager.h" |
| 18 #include "media/audio/audio_output_proxy.h" | 19 #include "media/audio/audio_output_proxy.h" |
| 19 #include "media/audio/audio_unittest_util.h" | 20 #include "media/audio/audio_unittest_util.h" |
| 20 #include "media/audio/fake_audio_log_factory.h" | 21 #include "media/audio/fake_audio_log_factory.h" |
| 21 #include "media/audio/fake_audio_manager.h" | 22 #include "media/audio/fake_audio_manager.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 #if defined(USE_ALSA) | 25 #if defined(USE_ALSA) |
| 25 #include "media/audio/alsa/audio_manager_alsa.h" | 26 #include "media/audio/alsa/audio_manager_alsa.h" |
| 26 #endif // defined(USE_ALSA) | 27 #endif // defined(USE_ALSA) |
| 27 | 28 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 AudioOutputStream* stream = | 83 AudioOutputStream* stream = |
| 83 audio_manager_->MakeAudioOutputStreamProxy(params, ""); | 84 audio_manager_->MakeAudioOutputStreamProxy(params, ""); |
| 84 ASSERT_TRUE(stream); | 85 ASSERT_TRUE(stream); |
| 85 AudioOutputDispatcher* dispatcher1 = | 86 AudioOutputDispatcher* dispatcher1 = |
| 86 reinterpret_cast<AudioOutputProxy*>(stream) | 87 reinterpret_cast<AudioOutputProxy*>(stream) |
| 87 ->get_dispatcher_for_testing(); | 88 ->get_dispatcher_for_testing(); |
| 88 | 89 |
| 89 // Closing this stream will put it up for reuse. | 90 // Closing this stream will put it up for reuse. |
| 90 stream->Close(); | 91 stream->Close(); |
| 91 stream = audio_manager_->MakeAudioOutputStreamProxy( | 92 stream = audio_manager_->MakeAudioOutputStreamProxy( |
| 92 params, AudioManagerBase::kDefaultDeviceId); | 93 params, AudioDeviceDescription::kDefaultDeviceId); |
| 93 | 94 |
| 94 // Verify both streams are created with the same dispatcher (which is unique | 95 // Verify both streams are created with the same dispatcher (which is unique |
| 95 // per device). | 96 // per device). |
| 96 ASSERT_EQ(dispatcher1, reinterpret_cast<AudioOutputProxy*>(stream) | 97 ASSERT_EQ(dispatcher1, reinterpret_cast<AudioOutputProxy*>(stream) |
| 97 ->get_dispatcher_for_testing()); | 98 ->get_dispatcher_for_testing()); |
| 98 stream->Close(); | 99 stream->Close(); |
| 99 | 100 |
| 100 // Create a non-default device and ensure it gets a different dispatcher. | 101 // Create a non-default device and ensure it gets a different dispatcher. |
| 101 stream = audio_manager_->MakeAudioOutputStreamProxy(params, "123456"); | 102 stream = audio_manager_->MakeAudioOutputStreamProxy(params, "123456"); |
| 102 ASSERT_NE(dispatcher1, reinterpret_cast<AudioOutputProxy*>(stream) | 103 ASSERT_NE(dispatcher1, reinterpret_cast<AudioOutputProxy*>(stream) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 #endif | 151 #endif |
| 151 | 152 |
| 152 // Helper method which verifies that the device list starts with a valid | 153 // Helper method which verifies that the device list starts with a valid |
| 153 // default record followed by non-default device names. | 154 // default record followed by non-default device names. |
| 154 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | 155 static void CheckDeviceNames(const AudioDeviceNames& device_names) { |
| 155 DVLOG(2) << "Got " << device_names.size() << " audio devices."; | 156 DVLOG(2) << "Got " << device_names.size() << " audio devices."; |
| 156 if (!device_names.empty()) { | 157 if (!device_names.empty()) { |
| 157 AudioDeviceNames::const_iterator it = device_names.begin(); | 158 AudioDeviceNames::const_iterator it = device_names.begin(); |
| 158 | 159 |
| 159 // The first device in the list should always be the default device. | 160 // The first device in the list should always be the default device. |
| 160 EXPECT_EQ(AudioManager::GetDefaultDeviceName(), it->device_name); | 161 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), |
| 161 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); | 162 it->device_name); |
| 163 EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId), |
| 164 it->unique_id); |
| 162 ++it; | 165 ++it; |
| 163 | 166 |
| 164 // Other devices should have non-empty name and id and should not contain | 167 // Other devices should have non-empty name and id and should not contain |
| 165 // default name or id. | 168 // default name or id. |
| 166 while (it != device_names.end()) { | 169 while (it != device_names.end()) { |
| 167 EXPECT_FALSE(it->device_name.empty()); | 170 EXPECT_FALSE(it->device_name.empty()); |
| 168 EXPECT_FALSE(it->unique_id.empty()); | 171 EXPECT_FALSE(it->unique_id.empty()); |
| 169 DVLOG(2) << "Device ID(" << it->unique_id | 172 DVLOG(2) << "Device ID(" << it->unique_id |
| 170 << "), label: " << it->device_name; | 173 << "), label: " << it->device_name; |
| 171 EXPECT_NE(AudioManager::GetDefaultDeviceName(), it->device_name); | 174 EXPECT_NE(AudioDeviceDescription::GetDefaultDeviceName(), |
| 172 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), | 175 it->device_name); |
| 176 EXPECT_NE(std::string(AudioDeviceDescription::kDefaultDeviceId), |
| 173 it->unique_id); | 177 it->unique_id); |
| 174 ++it; | 178 ++it; |
| 175 } | 179 } |
| 176 } else { | 180 } else { |
| 177 // Log a warning so we can see the status on the build bots. No need to | 181 // Log a warning so we can see the status on the build bots. No need to |
| 178 // break the test though since this does successfully test the code and | 182 // break the test though since this does successfully test the code and |
| 179 // some failure cases. | 183 // some failure cases. |
| 180 LOG(WARNING) << "No input devices detected"; | 184 LOG(WARNING) << "No input devices detected"; |
| 181 } | 185 } |
| 182 } | 186 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 DVLOG(2) << it->unique_id << " matches with " << output_device_id; | 426 DVLOG(2) << it->unique_id << " matches with " << output_device_id; |
| 423 found_an_associated_device = true; | 427 found_an_associated_device = true; |
| 424 } | 428 } |
| 425 } | 429 } |
| 426 | 430 |
| 427 EXPECT_TRUE(found_an_associated_device); | 431 EXPECT_TRUE(found_an_associated_device); |
| 428 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 432 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 429 } | 433 } |
| 430 | 434 |
| 431 } // namespace media | 435 } // namespace media |
| OLD | NEW |