| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/environment.h" | 6 #include "base/environment.h" |
| 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 "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "media/audio/audio_manager.h" | 10 #include "media/audio/audio_manager.h" |
| 11 #include "media/audio/audio_manager_base.h" | 11 #include "media/audio/audio_manager_base.h" |
| 12 #include "media/audio/audio_output_proxy.h" |
| 12 #include "media/audio/audio_unittest_util.h" | 13 #include "media/audio/audio_unittest_util.h" |
| 13 #include "media/audio/fake_audio_log_factory.h" | 14 #include "media/audio/fake_audio_log_factory.h" |
| 15 #include "media/audio/fake_audio_manager.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 #if defined(USE_ALSA) | 18 #if defined(USE_ALSA) |
| 17 #include "media/audio/alsa/audio_manager_alsa.h" | 19 #include "media/audio/alsa/audio_manager_alsa.h" |
| 18 #endif // defined(USE_ALSA) | 20 #endif // defined(USE_ALSA) |
| 19 | 21 |
| 20 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 21 #include "base/win/scoped_com_initializer.h" | 23 #include "base/win/scoped_com_initializer.h" |
| 22 #include "media/audio/win/audio_manager_win.h" | 24 #include "media/audio/win/audio_manager_win.h" |
| 23 #include "media/audio/win/wavein_input_win.h" | 25 #include "media/audio/win/wavein_input_win.h" |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 #if defined(USE_PULSEAUDIO) | 28 #if defined(USE_PULSEAUDIO) |
| 27 #include "media/audio/pulse/audio_manager_pulse.h" | 29 #include "media/audio/pulse/audio_manager_pulse.h" |
| 28 #endif // defined(USE_PULSEAUDIO) | 30 #endif // defined(USE_PULSEAUDIO) |
| 29 | 31 |
| 30 namespace media { | 32 namespace media { |
| 31 | 33 |
| 32 // Test fixture which allows us to override the default enumeration API on | 34 // Test fixture which allows us to override the default enumeration API on |
| 33 // Windows. | 35 // Windows. |
| 34 class AudioManagerTest : public ::testing::Test { | 36 class AudioManagerTest : public ::testing::Test { |
| 37 public: |
| 38 void HandleDefaultDeviceIDsTest() { |
| 39 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 40 CHANNEL_LAYOUT_STEREO, 48000, 16, 2048); |
| 41 |
| 42 // Create a stream with the default device id "". |
| 43 AudioOutputStream* stream = |
| 44 audio_manager_->MakeAudioOutputStreamProxy(params, ""); |
| 45 ASSERT_TRUE(stream); |
| 46 AudioOutputDispatcher* dispatcher1 = |
| 47 reinterpret_cast<AudioOutputProxy*>(stream) |
| 48 ->get_dispatcher_for_testing(); |
| 49 |
| 50 // Closing this stream will put it up for reuse. |
| 51 stream->Close(); |
| 52 stream = audio_manager_->MakeAudioOutputStreamProxy( |
| 53 params, AudioManagerBase::kDefaultDeviceId); |
| 54 |
| 55 // Verify both streams are created with the same dispatcher (which is unique |
| 56 // per device). |
| 57 ASSERT_EQ(dispatcher1, reinterpret_cast<AudioOutputProxy*>(stream) |
| 58 ->get_dispatcher_for_testing()); |
| 59 stream->Close(); |
| 60 |
| 61 // Create a non-default device and ensure it gets a different dispatcher. |
| 62 stream = audio_manager_->MakeAudioOutputStreamProxy(params, "123456"); |
| 63 ASSERT_NE(dispatcher1, reinterpret_cast<AudioOutputProxy*>(stream) |
| 64 ->get_dispatcher_for_testing()); |
| 65 stream->Close(); |
| 66 } |
| 67 |
| 35 protected: | 68 protected: |
| 36 AudioManagerTest() : audio_manager_(AudioManager::CreateForTesting()) { | 69 AudioManagerTest() : audio_manager_(AudioManager::CreateForTesting()) { |
| 37 // Wait for audio thread initialization to complete. Otherwise the | 70 // Wait for audio thread initialization to complete. Otherwise the |
| 38 // enumeration type may not have been set yet. | 71 // enumeration type may not have been set yet. |
| 39 base::WaitableEvent event(false, false); | 72 base::WaitableEvent event(false, false); |
| 40 audio_manager_->GetTaskRunner()->PostTask(FROM_HERE, base::Bind( | 73 audio_manager_->GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
| 41 &base::WaitableEvent::Signal, base::Unretained(&event))); | 74 &base::WaitableEvent::Signal, base::Unretained(&event))); |
| 42 event.Wait(); | 75 event.Wait(); |
| 43 } | 76 } |
| 44 | 77 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 base::WaitableEvent* event) { | 176 base::WaitableEvent* event) { |
| 144 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); | 177 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); |
| 145 closure.Run(); | 178 closure.Run(); |
| 146 event->Signal(); | 179 event->Signal(); |
| 147 } | 180 } |
| 148 | 181 |
| 149 FakeAudioLogFactory fake_audio_log_factory_; | 182 FakeAudioLogFactory fake_audio_log_factory_; |
| 150 scoped_ptr<AudioManager> audio_manager_; | 183 scoped_ptr<AudioManager> audio_manager_; |
| 151 }; | 184 }; |
| 152 | 185 |
| 186 TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) { |
| 187 // Use a fake manager so we can makeup device ids, this will still use the |
| 188 // AudioManagerBase code. |
| 189 audio_manager_.reset(new FakeAudioManager(&fake_audio_log_factory_)); |
| 190 RunOnAudioThread(base::Bind(&AudioManagerTest::HandleDefaultDeviceIDsTest, |
| 191 base::Unretained(this))); |
| 192 } |
| 193 |
| 153 // Test that devices can be enumerated. | 194 // Test that devices can be enumerated. |
| 154 TEST_F(AudioManagerTest, EnumerateInputDevices) { | 195 TEST_F(AudioManagerTest, EnumerateInputDevices) { |
| 155 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 196 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
| 156 | 197 |
| 157 AudioDeviceNames device_names; | 198 AudioDeviceNames device_names; |
| 158 RunOnAudioThread( | 199 RunOnAudioThread( |
| 159 base::Bind(&AudioManager::GetAudioInputDeviceNames, | 200 base::Bind(&AudioManager::GetAudioInputDeviceNames, |
| 160 base::Unretained(audio_manager_.get()), | 201 base::Unretained(audio_manager_.get()), |
| 161 &device_names)); | 202 &device_names)); |
| 162 CheckDeviceNames(device_names); | 203 CheckDeviceNames(device_names); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 DVLOG(2) << it->unique_id << " matches with " << output_device_id; | 400 DVLOG(2) << it->unique_id << " matches with " << output_device_id; |
| 360 found_an_associated_device = true; | 401 found_an_associated_device = true; |
| 361 } | 402 } |
| 362 } | 403 } |
| 363 | 404 |
| 364 EXPECT_TRUE(found_an_associated_device); | 405 EXPECT_TRUE(found_an_associated_device); |
| 365 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 406 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 366 } | 407 } |
| 367 | 408 |
| 368 } // namespace media | 409 } // namespace media |
| OLD | NEW |