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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/test/simple_test_tick_clock.h" | 11 #include "base/test/simple_test_tick_clock.h" |
12 #include "base/test/test_message_loop.h" | 12 #include "base/test/test_message_loop.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "media/audio/alsa/alsa_output.h" | 15 #include "media/audio/alsa/alsa_output.h" |
16 #include "media/audio/alsa/alsa_wrapper.h" | 16 #include "media/audio/alsa/alsa_wrapper.h" |
17 #include "media/audio/alsa/audio_manager_alsa.h" | 17 #include "media/audio/alsa/audio_manager_alsa.h" |
18 #include "media/audio/fake_audio_log_factory.h" | 18 #include "media/audio/fake_audio_log_factory.h" |
19 #include "media/audio/mock_audio_source_callback.h" | 19 #include "media/audio/mock_audio_source_callback.h" |
| 20 #include "media/audio/test_audio_thread.h" |
20 #include "media/base/audio_timestamp_helper.h" | 21 #include "media/base/audio_timestamp_helper.h" |
21 #include "media/base/data_buffer.h" | 22 #include "media/base/data_buffer.h" |
22 #include "media/base/seekable_buffer.h" | 23 #include "media/base/seekable_buffer.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using testing::_; | 27 using testing::_; |
27 using testing::AllOf; | 28 using testing::AllOf; |
28 using testing::AtLeast; | 29 using testing::AtLeast; |
29 using testing::DoAll; | 30 using testing::DoAll; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 MOCK_METHOD1(PcmAvailUpdate, snd_pcm_sframes_t(snd_pcm_t* handle)); | 74 MOCK_METHOD1(PcmAvailUpdate, snd_pcm_sframes_t(snd_pcm_t* handle)); |
74 MOCK_METHOD1(PcmState, snd_pcm_state_t(snd_pcm_t* handle)); | 75 MOCK_METHOD1(PcmState, snd_pcm_state_t(snd_pcm_t* handle)); |
75 MOCK_METHOD1(PcmStart, int(snd_pcm_t* handle)); | 76 MOCK_METHOD1(PcmStart, int(snd_pcm_t* handle)); |
76 | 77 |
77 MOCK_METHOD1(StrError, const char*(int errnum)); | 78 MOCK_METHOD1(StrError, const char*(int errnum)); |
78 }; | 79 }; |
79 | 80 |
80 class MockAudioManagerAlsa : public AudioManagerAlsa { | 81 class MockAudioManagerAlsa : public AudioManagerAlsa { |
81 public: | 82 public: |
82 MockAudioManagerAlsa() | 83 MockAudioManagerAlsa() |
83 : AudioManagerAlsa(base::ThreadTaskRunnerHandle::Get(), | 84 : AudioManagerAlsa(base::MakeUnique<TestAudioThread>(), |
84 base::ThreadTaskRunnerHandle::Get(), | |
85 &fake_audio_log_factory_) {} | 85 &fake_audio_log_factory_) {} |
86 MOCK_METHOD0(Init, void()); | 86 MOCK_METHOD0(Init, void()); |
87 MOCK_METHOD0(HasAudioOutputDevices, bool()); | 87 MOCK_METHOD0(HasAudioOutputDevices, bool()); |
88 MOCK_METHOD0(HasAudioInputDevices, bool()); | 88 MOCK_METHOD0(HasAudioInputDevices, bool()); |
89 MOCK_METHOD2(MakeLinearOutputStream, | 89 MOCK_METHOD2(MakeLinearOutputStream, |
90 AudioOutputStream*(const AudioParameters& params, | 90 AudioOutputStream*(const AudioParameters& params, |
91 const LogCallback& log_callback)); | 91 const LogCallback& log_callback)); |
92 MOCK_METHOD3(MakeLowLatencyOutputStream, | 92 MOCK_METHOD3(MakeLowLatencyOutputStream, |
93 AudioOutputStream*(const AudioParameters& params, | 93 AudioOutputStream*(const AudioParameters& params, |
94 const std::string& device_id, | 94 const std::string& device_id, |
(...skipping 15 matching lines...) Expand all Loading... |
110 private: | 110 private: |
111 FakeAudioLogFactory fake_audio_log_factory_; | 111 FakeAudioLogFactory fake_audio_log_factory_; |
112 }; | 112 }; |
113 | 113 |
114 class AlsaPcmOutputStreamTest : public testing::Test { | 114 class AlsaPcmOutputStreamTest : public testing::Test { |
115 protected: | 115 protected: |
116 AlsaPcmOutputStreamTest() { | 116 AlsaPcmOutputStreamTest() { |
117 mock_manager_.reset(new StrictMock<MockAudioManagerAlsa>()); | 117 mock_manager_.reset(new StrictMock<MockAudioManagerAlsa>()); |
118 } | 118 } |
119 | 119 |
120 virtual ~AlsaPcmOutputStreamTest() { | 120 virtual ~AlsaPcmOutputStreamTest() { mock_manager_->Shutdown(); } |
121 } | |
122 | 121 |
123 AlsaPcmOutputStream* CreateStream(ChannelLayout layout) { | 122 AlsaPcmOutputStream* CreateStream(ChannelLayout layout) { |
124 return CreateStream(layout, kTestFramesPerPacket); | 123 return CreateStream(layout, kTestFramesPerPacket); |
125 } | 124 } |
126 | 125 |
127 AlsaPcmOutputStream* CreateStream(ChannelLayout layout, | 126 AlsaPcmOutputStream* CreateStream(ChannelLayout layout, |
128 int32_t samples_per_packet) { | 127 int32_t samples_per_packet) { |
129 AudioParameters params(kTestFormat, layout, kTestSampleRate, | 128 AudioParameters params(kTestFormat, layout, kTestSampleRate, |
130 kTestBitsPerSample, samples_per_packet); | 129 kTestBitsPerSample, samples_per_packet); |
131 return new AlsaPcmOutputStream(kTestDeviceName, | 130 return new AlsaPcmOutputStream(kTestDeviceName, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 static char kSurround41[]; | 170 static char kSurround41[]; |
172 static char kSurround50[]; | 171 static char kSurround50[]; |
173 static char kSurround51[]; | 172 static char kSurround51[]; |
174 static char kSurround70[]; | 173 static char kSurround70[]; |
175 static char kSurround71[]; | 174 static char kSurround71[]; |
176 static void* kFakeHints[]; | 175 static void* kFakeHints[]; |
177 static char kGenericSurround50[]; | 176 static char kGenericSurround50[]; |
178 | 177 |
179 base::TestMessageLoop message_loop_; | 178 base::TestMessageLoop message_loop_; |
180 StrictMock<MockAlsaWrapper> mock_alsa_wrapper_; | 179 StrictMock<MockAlsaWrapper> mock_alsa_wrapper_; |
181 std::unique_ptr<StrictMock<MockAudioManagerAlsa>, AudioManagerDeleter> | 180 std::unique_ptr<StrictMock<MockAudioManagerAlsa>> mock_manager_; |
182 mock_manager_; | |
183 scoped_refptr<DataBuffer> packet_; | 181 scoped_refptr<DataBuffer> packet_; |
184 | 182 |
185 private: | 183 private: |
186 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStreamTest); | 184 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStreamTest); |
187 }; | 185 }; |
188 | 186 |
189 const ChannelLayout AlsaPcmOutputStreamTest::kTestChannelLayout = | 187 const ChannelLayout AlsaPcmOutputStreamTest::kTestChannelLayout = |
190 CHANNEL_LAYOUT_STEREO; | 188 CHANNEL_LAYOUT_STEREO; |
191 const int AlsaPcmOutputStreamTest::kTestSampleRate = | 189 const int AlsaPcmOutputStreamTest::kTestSampleRate = |
192 AudioParameters::kAudioCDSampleRate; | 190 AudioParameters::kAudioCDSampleRate; |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 | 864 |
867 // TODO(ajwong): Find a way to test whether or not another task has been | 865 // TODO(ajwong): Find a way to test whether or not another task has been |
868 // posted so we can verify that the Alsa code will indeed break the task | 866 // posted so we can verify that the Alsa code will indeed break the task |
869 // posting loop. | 867 // posting loop. |
870 | 868 |
871 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); | 869 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); |
872 test_stream->Close(); | 870 test_stream->Close(); |
873 } | 871 } |
874 | 872 |
875 } // namespace media | 873 } // namespace media |
OLD | NEW |