| 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "media/audio/audio_io.h" | 9 #include "media/audio/audio_io.h" |
| 10 #include "media/audio/audio_manager_base.h" | 10 #include "media/audio/audio_manager_base.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 // Sleep 100ms to wait for the operation. | 32 // Sleep 100ms to wait for the operation. |
| 33 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 33 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 return volume; | 36 return volume; |
| 37 } | 37 } |
| 38 | 38 |
| 39 class AudioInputVolumeTest : public ::testing::Test { | 39 class AudioInputVolumeTest : public ::testing::Test { |
| 40 protected: | 40 protected: |
| 41 AudioInputVolumeTest() : audio_manager_(AudioManager::CreateForTesting()) {} | 41 AudioInputVolumeTest() |
| 42 : audio_manager_(AudioManager::CreateForTesting()) |
| 43 #if defined(OS_WIN) |
| 44 , com_init_(base::win::ScopedCOMInitializer::kMTA) |
| 45 #endif |
| 46 { |
| 47 } |
| 42 | 48 |
| 43 bool HasCoreAudioAndInputDevices() { | 49 bool HasCoreAudioAndInputDevices() { |
| 44 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 45 // TODO(henrika): add support for volume control on Windows XP as well. | 51 // TODO(henrika): add support for volume control on Windows XP as well. |
| 46 if (!CoreAudioUtil::IsSupported()) | 52 if (!CoreAudioUtil::IsSupported()) |
| 47 return false; | 53 return false; |
| 48 #endif | 54 #endif |
| 49 return audio_manager_->HasAudioInputDevices(); | 55 return audio_manager_->HasAudioInputDevices(); |
| 50 } | 56 } |
| 51 | 57 |
| 52 // Helper method which checks if the stream has volume support. | 58 // Helper method which checks if the stream has volume support. |
| 53 bool HasDeviceVolumeControl(AudioInputStream* stream) { | 59 bool HasDeviceVolumeControl(AudioInputStream* stream) { |
| 54 if (!stream) | 60 if (!stream) |
| 55 return false; | 61 return false; |
| 56 | 62 |
| 57 return (stream->GetMaxVolume() != 0.0); | 63 return (stream->GetMaxVolume() != 0.0); |
| 58 } | 64 } |
| 59 | 65 |
| 60 AudioInputStream* CreateAndOpenStream(const std::string& device_id) { | 66 AudioInputStream* CreateAndOpenStream(const std::string& device_id) { |
| 61 const AudioParameters& params = | 67 const AudioParameters& params = |
| 62 audio_manager_->GetInputStreamParameters(device_id); | 68 audio_manager_->GetInputStreamParameters(device_id); |
| 63 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 69 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
| 64 params, device_id); | 70 params, device_id); |
| 65 EXPECT_TRUE(NULL != ais); | 71 EXPECT_TRUE(NULL != ais); |
| 66 | 72 |
| 67 #if defined(OS_MACOSX) | 73 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 68 EXPECT_TRUE(ais->Open()); | 74 // Some linux devices do not support our settings, we may fail to open |
| 69 #else | 75 // those devices. |
| 70 // Some linux devices do not support our settings and some Windows devices | |
| 71 // may be "currently unavailable", we may fail to open those devices. | |
| 72 if (!ais->Open()) { | 76 if (!ais->Open()) { |
| 73 // Default device should always be able to be opened. | 77 // Default device should always be able to be opened. |
| 74 EXPECT_TRUE(AudioManagerBase::kDefaultDeviceId != device_id); | 78 EXPECT_TRUE(AudioManagerBase::kDefaultDeviceId != device_id); |
| 75 ais->Close(); | 79 ais->Close(); |
| 76 ais = NULL; | 80 ais = NULL; |
| 77 } | 81 } |
| 82 #elif defined(OS_WIN) || defined(OS_MACOSX) |
| 83 EXPECT_TRUE(ais->Open()); |
| 78 #endif | 84 #endif |
| 79 | 85 |
| 80 return ais; | 86 return ais; |
| 81 } | 87 } |
| 82 | 88 |
| 89 scoped_ptr<AudioManager> audio_manager_; |
| 90 |
| 83 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
| 84 base::win::ScopedCOMInitializer com_init_; | 92 base::win::ScopedCOMInitializer com_init_; |
| 85 #endif | 93 #endif |
| 86 | |
| 87 scoped_ptr<AudioManager> audio_manager_; | |
| 88 }; | 94 }; |
| 89 | 95 |
| 90 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 96 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 91 // Currently failing on linux ARM bot: http://crbug/238490 | 97 // Currently failing on linux ARM bot: http://crbug/238490 |
| 92 // Also flaky on x86_64: http://crbug/236936 | 98 // Also flaky on x86_64: http://crbug/236936 |
| 93 #define MAYBE_InputVolumeTest DISABLED_InputVolumeTest | 99 #define MAYBE_InputVolumeTest DISABLED_InputVolumeTest |
| 94 #else | 100 #else |
| 95 #define MAYBE_InputVolumeTest InputVolumeTest | 101 #define MAYBE_InputVolumeTest InputVolumeTest |
| 96 #endif | 102 #endif |
| 97 | 103 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // Restores the volume to the original value. | 171 // Restores the volume to the original value. |
| 166 ais->SetVolume(original_volume); | 172 ais->SetVolume(original_volume); |
| 167 current_volume = ais->GetVolume(); | 173 current_volume = ais->GetVolume(); |
| 168 EXPECT_EQ(original_volume, current_volume); | 174 EXPECT_EQ(original_volume, current_volume); |
| 169 | 175 |
| 170 ais->Close(); | 176 ais->Close(); |
| 171 } | 177 } |
| 172 } | 178 } |
| 173 | 179 |
| 174 } // namespace media | 180 } // namespace media |
| OLD | NEW |