| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // Helper method which checks if the stream has volume support. | 45 // Helper method which checks if the stream has volume support. |
| 46 bool HasDeviceVolumeControl(AudioInputStream* stream) { | 46 bool HasDeviceVolumeControl(AudioInputStream* stream) { |
| 47 if (!stream) | 47 if (!stream) |
| 48 return false; | 48 return false; |
| 49 | 49 |
| 50 return (stream->GetMaxVolume() != 0.0); | 50 return (stream->GetMaxVolume() != 0.0); |
| 51 } | 51 } |
| 52 | 52 |
| 53 AudioInputStream* CreateAndOpenStream(const std::string& device_id) { | 53 AudioInputStream* CreateAndOpenStream(const std::string& device_id) { |
| 54 AudioParameters::Format format = AudioParameters::AUDIO_PCM_LOW_LATENCY; | 54 const AudioParameters& params = |
| 55 ChannelLayout channel_layout = | 55 audio_manager_->GetInputStreamParameters(device_id); |
| 56 media::GetAudioInputHardwareChannelLayout(device_id); | |
| 57 int bits_per_sample = 16; | |
| 58 int sample_rate = | |
| 59 static_cast<int>(media::GetAudioInputHardwareSampleRate(device_id)); | |
| 60 int samples_per_packet = 0; | |
| 61 #if defined(OS_MACOSX) | |
| 62 samples_per_packet = (sample_rate / 100); | |
| 63 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 64 samples_per_packet = (sample_rate / 100); | |
| 65 #elif defined(OS_WIN) | |
| 66 if (sample_rate == 44100) | |
| 67 samples_per_packet = 448; | |
| 68 else | |
| 69 samples_per_packet = (sample_rate / 100); | |
| 70 #else | |
| 71 #error Unsupported platform | |
| 72 #endif | |
| 73 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 56 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
| 74 AudioParameters(format, channel_layout, sample_rate, bits_per_sample, | 57 params, device_id); |
| 75 samples_per_packet), | |
| 76 device_id); | |
| 77 EXPECT_TRUE(NULL != ais); | 58 EXPECT_TRUE(NULL != ais); |
| 78 | 59 |
| 79 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 60 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 80 // Some linux devices do not support our settings, we may fail to open | 61 // Some linux devices do not support our settings, we may fail to open |
| 81 // those devices. | 62 // those devices. |
| 82 if (!ais->Open()) { | 63 if (!ais->Open()) { |
| 83 // Default device should always be able to be opened. | 64 // Default device should always be able to be opened. |
| 84 EXPECT_TRUE(AudioManagerBase::kDefaultDeviceId != device_id); | 65 EXPECT_TRUE(AudioManagerBase::kDefaultDeviceId != device_id); |
| 85 ais->Close(); | 66 ais->Close(); |
| 86 ais = NULL; | 67 ais = NULL; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // Restores the volume to the original value. | 143 // Restores the volume to the original value. |
| 163 ais->SetVolume(original_volume); | 144 ais->SetVolume(original_volume); |
| 164 current_volume = ais->GetVolume(); | 145 current_volume = ais->GetVolume(); |
| 165 EXPECT_EQ(original_volume, current_volume); | 146 EXPECT_EQ(original_volume, current_volume); |
| 166 | 147 |
| 167 ais->Close(); | 148 ais->Close(); |
| 168 } | 149 } |
| 169 } | 150 } |
| 170 | 151 |
| 171 } // namespace media | 152 } // namespace media |
| OLD | NEW |