Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: media/audio/audio_input_volume_unittest.cc

Issue 1097553003: Switch to STA mode for audio thread and WASAPI I/O streams. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/audio/audio_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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() 41 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 42
49 bool HasCoreAudioAndInputDevices() { 43 bool HasCoreAudioAndInputDevices() {
50 #if defined(OS_WIN) 44 #if defined(OS_WIN)
51 // TODO(henrika): add support for volume control on Windows XP as well. 45 // TODO(henrika): add support for volume control on Windows XP as well.
52 if (!CoreAudioUtil::IsSupported()) 46 if (!CoreAudioUtil::IsSupported())
53 return false; 47 return false;
54 #endif 48 #endif
55 return audio_manager_->HasAudioInputDevices(); 49 return audio_manager_->HasAudioInputDevices();
56 } 50 }
57 51
58 // Helper method which checks if the stream has volume support. 52 // Helper method which checks if the stream has volume support.
59 bool HasDeviceVolumeControl(AudioInputStream* stream) { 53 bool HasDeviceVolumeControl(AudioInputStream* stream) {
60 if (!stream) 54 if (!stream)
61 return false; 55 return false;
62 56
63 return (stream->GetMaxVolume() != 0.0); 57 return (stream->GetMaxVolume() != 0.0);
64 } 58 }
65 59
66 AudioInputStream* CreateAndOpenStream(const std::string& device_id) { 60 AudioInputStream* CreateAndOpenStream(const std::string& device_id) {
67 const AudioParameters& params = 61 const AudioParameters& params =
68 audio_manager_->GetInputStreamParameters(device_id); 62 audio_manager_->GetInputStreamParameters(device_id);
69 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( 63 AudioInputStream* ais = audio_manager_->MakeAudioInputStream(
70 params, device_id); 64 params, device_id);
71 EXPECT_TRUE(NULL != ais); 65 EXPECT_TRUE(NULL != ais);
72 66
73 #if defined(OS_LINUX) || defined(OS_OPENBSD) 67 #if defined(OS_MACOSX)
74 // Some linux devices do not support our settings, we may fail to open 68 EXPECT_TRUE(ais->Open());
75 // those devices. 69 #else
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.
76 if (!ais->Open()) { 72 if (!ais->Open()) {
77 // Default device should always be able to be opened. 73 // Default device should always be able to be opened.
78 EXPECT_TRUE(AudioManagerBase::kDefaultDeviceId != device_id); 74 EXPECT_TRUE(AudioManagerBase::kDefaultDeviceId != device_id);
79 ais->Close(); 75 ais->Close();
80 ais = NULL; 76 ais = NULL;
81 } 77 }
82 #elif defined(OS_WIN) || defined(OS_MACOSX)
83 EXPECT_TRUE(ais->Open());
84 #endif 78 #endif
85 79
86 return ais; 80 return ais;
87 } 81 }
88 82
89 scoped_ptr<AudioManager> audio_manager_;
90
91 #if defined(OS_WIN) 83 #if defined(OS_WIN)
92 base::win::ScopedCOMInitializer com_init_; 84 base::win::ScopedCOMInitializer com_init_;
93 #endif 85 #endif
86
87 scoped_ptr<AudioManager> audio_manager_;
94 }; 88 };
95 89
96 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 90 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
97 // Currently failing on linux ARM bot: http://crbug/238490 91 // Currently failing on linux ARM bot: http://crbug/238490
98 // Also flaky on x86_64: http://crbug/236936 92 // Also flaky on x86_64: http://crbug/236936
99 #define MAYBE_InputVolumeTest DISABLED_InputVolumeTest 93 #define MAYBE_InputVolumeTest DISABLED_InputVolumeTest
100 #else 94 #else
101 #define MAYBE_InputVolumeTest InputVolumeTest 95 #define MAYBE_InputVolumeTest InputVolumeTest
102 #endif 96 #endif
103 97
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Restores the volume to the original value. 165 // Restores the volume to the original value.
172 ais->SetVolume(original_volume); 166 ais->SetVolume(original_volume);
173 current_volume = ais->GetVolume(); 167 current_volume = ais->GetVolume();
174 EXPECT_EQ(original_volume, current_volume); 168 EXPECT_EQ(original_volume, current_volume);
175 169
176 ais->Close(); 170 ais->Close();
177 } 171 }
178 } 172 }
179 173
180 } // namespace media 174 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698