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